List of usage examples for android.location Address setLongitude
public void setLongitude(double longitude)
From source file:it.smartcampuslab.riciclo.geo.OSMAddress.java
/** * Convert the object to {@link Address} data structure * @return converted {@link Address} instance with * address line corresponding to the formatted address of the object * with lat/lon, country name, and locality filled. *///from w w w. j a v a 2s. c o m public Address toAddress() { Address a = new Address(locale); a.setAddressLine(0, formattedAddress()); a.setCountryName(country()); a.setLatitude(location[0]); a.setLongitude(location[1]); a.setLocality(city()); return a; }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.fragments.event.EventDetailsFragment.java
/** * /*from ww w .j av a 2s. c om*/ */ protected void callBringMeThere() { Address to = new Address(Locale.getDefault()); to.setLatitude(mEvent.getLocation()[0]); to.setLongitude(mEvent.getLocation()[1]); Address from = null; GeoPoint mylocation = MapManager.requestMyLocation(getActivity()); if (mylocation != null) { from = new Address(Locale.getDefault()); from.setLatitude(mylocation.getLatitudeE6() / 1E6); from.setLongitude(mylocation.getLongitudeE6() / 1E6); } DTHelper.bringmethere(getActivity(), from, to); }
From source file:edu.usf.cutr.opentripplanner.android.tasks.OTPGeocoding.java
private ArrayList<Address> searchPlaces(String name) { HashMap<String, String> params = new HashMap<String, String>(); Places p;// www . java 2s. c om /*params.put(Itract.PARAM_NAME, name); if (selectedServer != null) { params.put(Itract.PARAM_LAT, Double.toString(selectedServer.getGeometricalCenterLatitude())); params.put(Itract.PARAM_LON, Double.toString(selectedServer.getGeometricalCenterLongitude())); } p = new Itract();*/ if (placesService.equals(context.getResources().getString(R.string.geocoder_google_places))) { params.put(GooglePlaces.PARAM_NAME, name); if (selectedServer != null) { params.put(GooglePlaces.PARAM_LOCATION, Double.toString(selectedServer.getGeometricalCenterLatitude()) + "," + Double.toString(selectedServer.getGeometricalCenterLongitude())); params.put(GooglePlaces.PARAM_RADIUS, Double.toString(selectedServer.getRadius())); } p = new GooglePlaces(getKeyFromResource()); Log.v(TAG, "Using Google Places!"); } else { params.put(Nominatim.PARAM_NAME, name); if (selectedServer != null) { params.put(Nominatim.PARAM_LEFT, Double.toString(selectedServer.getLowerLeftLongitude())); params.put(Nominatim.PARAM_TOP, Double.toString(selectedServer.getLowerLeftLatitude())); params.put(Nominatim.PARAM_RIGHT, Double.toString(selectedServer.getUpperRightLongitude())); params.put(Nominatim.PARAM_BOTTOM, Double.toString(selectedServer.getUpperRightLatitude())); } p = new Nominatim(); Log.v(TAG, "Using Nominatim!"); } ArrayList<POI> pois = new ArrayList<POI>(); pois.addAll(p.getPlaces(params)); ArrayList<Address> addresses = new ArrayList<Address>(); for (int i = 0; i < pois.size(); i++) { POI poi = pois.get(i); Log.v(TAG, poi.getName() + " " + poi.getLatitude() + "," + poi.getLongitude()); Address addr = new Address(context.getResources().getConfiguration().locale); addr.setLatitude(poi.getLatitude()); addr.setLongitude(poi.getLongitude()); String addressLine; if (poi.getAddress() != null) { if (!poi.getAddress().contains(poi.getName())) { addressLine = (poi.getName() + ", " + poi.getAddress()); } else { addressLine = poi.getAddress(); } } else { addressLine = poi.getName(); } addr.setAddressLine(addr.getMaxAddressLineIndex() + 1, addressLine); addresses.add(addr); } return addresses; }
From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.track.TrackDetailsFragment.java
@Override public void onStart() { super.onStart(); if (getTrack() != null) { ImageView certifiedIcon = (ImageView) this.getView().findViewById(R.id.track_details_icon); Drawable icon = null;/*from w w w . ja va 2s . c o m*/ certifiedIcon .setImageDrawable(getResources().getDrawable(CategoryHelper.getIconByType(mTrack.getType()))); // title TextView tv = (TextView) this.getView().findViewById(R.id.track_details_title); tv.setText(mTrack.getTitle()); /* * BUTTONS */ // map ImageButton mapBtn = (ImageButton) getView().findViewById(R.id.trackdetails_map); mapBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ArrayList<BaseDTObject> list = new ArrayList<BaseDTObject>(); list.add(mTrack); MapManager.switchToMapView(list, mFragment); } }); // directions ImageButton directionsBtn = (ImageButton) getView().findViewById(R.id.trackdetails_directions); directionsBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Address to = Utils.getTrackAsGoogleAddress(mTrack); Address from = null; GeoPoint mylocation = MapManager.requestMyLocation(getActivity()); if (mylocation != null) { from = new Address(Locale.getDefault()); from.setLatitude(mylocation.getLatitudeE6() / 1E6); from.setLongitude(mylocation.getLongitudeE6() / 1E6); } DTHelper.bringmethere(getActivity(), from, to); } }); /* * END BUTTONS */ // description, optional tv = (TextView) this.getView().findViewById(R.id.track_details_descr); String customDescr = mTrack.customDescription(getActivity()); if (customDescr != null && customDescr.length() > 0) { tv.setText(Html.fromHtml(customDescr)); } else { ((LinearLayout) this.getView().findViewById(R.id.trackdetails)).removeView(tv); } commentsHandler = new CommentsHandler(getTrack(), getActivity(), getView()); } }
From source file:edu.usf.cutr.opentripplanner.android.tasks.OTPGeocoding.java
protected Long doInBackground(String... reqs) { long count = reqs.length; String address = reqs[0];/* w w w.j a v a 2 s . com*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (address == null || address.equalsIgnoreCase("")) { return count; } if (address.equalsIgnoreCase(context.getString(R.string.my_location))) { String currentLat = reqs[1]; String currentLng = reqs[2]; LatLng latLng = new LatLng(Double.parseDouble(currentLat), Double.parseDouble(currentLng)); Address addressReturn = new Address(context.getResources().getConfiguration().locale); addressReturn.setLatitude(latLng.latitude); addressReturn.setLongitude(latLng.longitude); addressReturn.setAddressLine(addressReturn.getMaxAddressLineIndex() + 1, context.getString(R.string.my_location)); addressesReturn.add(addressReturn); return count; } ArrayList<Address> addresses = null; if (prefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_ANDROID_GEOCODER, true)) { Log.d("test", "create a geocoder"); Geocoder gc = new Geocoder(context); try { if (selectedServer != null) { addresses = (ArrayList<Address>) gc.getFromLocationName(address, context.getResources().getInteger(R.integer.geocoder_max_results), selectedServer.getLowerLeftLatitude(), selectedServer.getLowerLeftLongitude(), selectedServer.getUpperRightLatitude(), selectedServer.getUpperRightLongitude()); } else { addresses = (ArrayList<Address>) gc.getFromLocationName(address, context.getResources().getInteger(R.integer.geocoder_max_results)); } } catch (IOException e) { e.printStackTrace(); } } addresses = filterAddressesBBox(addresses); if ((addresses == null) || addresses.isEmpty()) { addresses = searchPlaces(address); for (int i = 0; i < addresses.size(); i++) { Address addr = addresses.get(i); String str = addr.getAddressLine(0); List<String> addrLines = Arrays.asList(str.split(", ")); for (int j = 0; j < addrLines.size(); j++) { addr.setAddressLine(j, addrLines.get(j)); } } } addresses = filterAddressesBBox(addresses); addressesReturn.addAll(addresses); return count; }
From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.poi.PoiDetailsFragment.java
@Override public void onStart() { super.onStart(); if (getPOI() != null) { ImageView certifiedIcon = (ImageView) this.getView().findViewById(R.id.poi_details_icon); ImageView bannerCertifiedIcon = (ImageView) this.getView().findViewById(R.id.banner_certified); Drawable icon = null;/*from www. j a v a 2s .c o m*/ if (CategoryHelper.CAT_POI_FAMILY_IN_TRENTINO.equals(mPoi.getType())) { icon = POIHelper.getDrawablePoiFamilyTrentinoDetail(getActivity(), mPoi); bannerCertifiedIcon.setVisibility(View.VISIBLE); } else if (CategoryHelper.CAT_POI_FAMILY_AUDIT.equals(mPoi.getType())) { icon = POIHelper.getDrawablePoiFamilyAuditDetail(getActivity(), mPoi); bannerCertifiedIcon.setVisibility(View.VISIBLE); } certifiedIcon.setImageDrawable(icon); // title TextView tv = (TextView) this.getView().findViewById(R.id.poi_details_title); tv.setText(mPoi.getTitle()); /* * BUTTONS */ // map ImageButton mapBtn = (ImageButton) getView().findViewById(R.id.poidetails_map); mapBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ArrayList<BaseDTObject> list = new ArrayList<BaseDTObject>(); list.add(mPoi); MapManager.switchToMapView(list, mFragment); } }); // directions ImageButton directionsBtn = (ImageButton) getView().findViewById(R.id.poidetails_directions); directionsBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Address to = Utils.getPOIasGoogleAddress(mPoi); Address from = null; GeoPoint mylocation = MapManager.requestMyLocation(getActivity()); if (mylocation != null) { from = new Address(Locale.getDefault()); from.setLatitude(mylocation.getLatitudeE6() / 1E6); from.setLongitude(mylocation.getLongitudeE6() / 1E6); } DTHelper.bringmethere(getActivity(), from, to); } }); if (mPoi.getLocation()[0] == 0 && mPoi.getLocation()[1] == 0) { mapBtn.setVisibility(View.INVISIBLE); directionsBtn.setVisibility(View.GONE); } /* * END BUTTONS */ // description, optional tv = (TextView) this.getView().findViewById(R.id.poi_details_descr); String customDesc = POIHelper.customDescription(mPoi, getActivity()); if (customDesc != null && customDesc.length() > 0) { tv.setText(Html.fromHtml(customDesc)); } else { ((LinearLayout) this.getView().findViewById(R.id.poidetails)).removeView(tv); } // // notes // tv = (TextView) this.getView().findViewById(R.id.poi_details_notes); // ((LinearLayout) this.getView().findViewById(R.id.poidetails)).removeView(tv); // location tv = (TextView) this.getView().findViewById(R.id.poi_details_loc); tv.setText(Html.fromHtml("<a href=\"\">" + Utils.getPOIshortAddress(mPoi) + "</a> ")); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ArrayList<BaseDTObject> list = new ArrayList<BaseDTObject>(); list.add(mPoi); MapManager.switchToMapView(list, PoiDetailsFragment.this); } }); commentsHandler = new CommentsHandler(getPOI(), getActivity(), getView()); } }
From source file:eu.trentorise.smartcampus.jp.PlanNewJourneyFragment.java
private void findAddressForField(final String field, Location location) { List<Address> hereAddressesList = new SCGeocoder(getSherlockActivity()).findAddressesAsync(location); if (hereAddressesList != null && !hereAddressesList.isEmpty()) { Address hereAddress = hereAddressesList.get(0); savePosition(hereAddress, field); } else {/* w w w.j ava 2 s . com*/ Address customAddress = new Address(Locale.getDefault()); customAddress.setLatitude(location.getLatitude()); customAddress.setLongitude(location.getLongitude()); customAddress.setAddressLine(0, "LON " + Double.toString(customAddress.getLongitude()) + ", LAT " + Double.toString(customAddress.getLatitude())); savePosition(customAddress, field); } }
From source file:eu.trentorise.smartcampus.jp.PlanNewJourneyFragment.java
protected void createFavoritesDialog(final String field) { if (userPrefsHolder != null && userPrefsHolder.getFavorites() != null && !userPrefsHolder.getFavorites().isEmpty()) { final List<Position> list = userPrefsHolder.getFavorites(); String[] items = new String[list.size()]; for (int i = 0; i < items.length; i++) { items[i] = list.get(i).getName(); }// ww w. j a v a 2 s. co m AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity()); builder.setTitle(getString(R.string.favorites_title)); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // to be replaced with real favorites list Address address = new Address(Locale.getDefault()); Position p = list.get(which); address.setLatitude(Double.parseDouble(p.getLat())); address.setLongitude(Double.parseDouble(p.getLon())); address.setAddressLine(0, p.getName()); savePosition(address, field); if (FROM.equalsIgnoreCase(field)) { ImageButton ibtn = (ImageButton) getView().findViewById(R.id.plannew_from_star); ibtn.setImageResource(R.drawable.ic_fav_star_active); ibtn.setTag(true); } else if (TO.equalsIgnoreCase(field)) { ImageButton ibtn = (ImageButton) getView().findViewById(R.id.plannew_to_star); ibtn.setImageResource(R.drawable.ic_fav_star_active); ibtn.setTag(true); } } }); builder.create().show(); } else { Toast.makeText(getActivity(), R.string.favorites_empty_list, Toast.LENGTH_SHORT).show(); } }
From source file:eu.trentorise.smartcampus.jp.PlanNewJourneyFragment.java
private Address getLocationsFromParam(String param, Address from, Map<String, List<String>> locations, String fromString) {/*w ww . ja v a2 s .c o m*/ if (locations.containsKey(param)) { fromString = locations.get(param).get(0); } if (fromString != null) { from = new Address(Locale.getDefault()); List<String> fromList = Arrays.asList(fromString.split(",")); Log.e(getClass().getSimpleName(), fromString); from.setLatitude(Double.parseDouble(fromList.get(0))); from.setLongitude(Double.parseDouble(fromList.get(1))); } return from; }
From source file:grandroid.geo.Geocoder.java
public static List<Address> getFromLocation(Locale locale, double lat, double lng, int maxResult) { String language = locale.getLanguage(); if (locale == Locale.TAIWAN) { language = "zh-TW"; }/*from w w w . j av a 2 s .com*/ String address = String.format(locale, "http://maps.googleapis.com/maps/api/geocode/json?latlng=%1$f,%2$f&sensor=false&language=" + language, lat, lng);//locale.getCountry() HttpGet httpGet = new HttpGet(address); HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(AllClientPNames.USER_AGENT, "Mozilla/5.0 (Java) Gecko/20081007 java-geocoder"); //client.getParams().setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 5 * 1000); //client.getParams().setIntParameter(AllClientPNames.SO_TIMEOUT, 25 * 1000); HttpResponse response; List<Address> retList = null; try { response = client.execute(httpGet); HttpEntity entity = response.getEntity(); String json = EntityUtils.toString(entity, "UTF-8"); JSONObject jsonObject = new JSONObject(json); retList = new ArrayList<Address>(); if ("OK".equalsIgnoreCase(jsonObject.getString("status"))) { JSONArray results = jsonObject.getJSONArray("results"); if (results.length() > 0) { for (int i = 0; i < results.length() && i < maxResult; i++) { JSONObject result = results.getJSONObject(i); //Log.e(MyGeocoder.class.getName(), result.toString()); Address addr = new Address(Locale.getDefault()); // addr.setAddressLine(0, result.getString("formatted_address")); JSONArray components = result.getJSONArray("address_components"); String streetNumber = ""; String route = ""; for (int a = 0; a < components.length(); a++) { JSONObject component = components.getJSONObject(a); JSONArray types = component.getJSONArray("types"); for (int j = 0; j < types.length(); j++) { String type = types.getString(j); if (type.equals("locality") || type.equals("administrative_area_level_3")) { addr.setLocality(component.getString("long_name")); } else if (type.equals("street_number")) { streetNumber = component.getString("long_name"); } else if (type.equals("route")) { route = component.getString("long_name"); } else if (type.equals("administrative_area_level_1")) { addr.setAdminArea(component.getString("long_name")); } else if (type.equals("country")) { addr.setCountryName(component.getString("long_name")); addr.setCountryCode(component.getString("short_name")); } } } addr.setAddressLine(0, route + " " + streetNumber); if (result.has("formatted_address")) { addr.setFeatureName(result.getString("formatted_address")); } addr.setLatitude( result.getJSONObject("geometry").getJSONObject("location").getDouble("lat")); addr.setLongitude( result.getJSONObject("geometry").getJSONObject("location").getDouble("lng")); if (addr.getAdminArea() == null) { addr.setAdminArea(""); } retList.add(addr); } } } } catch (ClientProtocolException e) { Log.e("grandroid", "Error calling Google geocode webservice.", e); } catch (IOException e) { Log.e("grandroid", "Error calling Google geocode webservice.", e); } catch (JSONException e) { Log.e("grandroid", "Error parsing Google geocode webservice response.", e); } return retList; }