List of usage examples for android.location Geocoder getFromLocationName
public List<Address> getFromLocationName(String locationName, int maxResults) throws IOException
From source file:Main.java
public static double getLonByLocation(Context context, String ciudad) { Geocoder geocoder = new Geocoder(context); try {/* www . j a v a 2s. c om*/ List<Address> result = geocoder.getFromLocationName(ciudad, 1); if (result != null && result.isEmpty() == false) { return result.get(0).getLongitude(); } } catch (IOException e) { return 0D; } return 0D; }
From source file:com.dycody.android.idealnote.utils.GeocodeHelper.java
public static double[] getCoordinatesFromAddress(Context mContext, String address) throws IOException { double[] result = new double[2]; Geocoder geocoder = new Geocoder(mContext, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocationName(address, 1); if (addresses.size() > 0) { double latitude = addresses.get(0).getLatitude(); double longitude = addresses.get(0).getLongitude(); result[0] = latitude;/*w w w . j a v a 2 s . c om*/ result[1] = longitude; } return result; }
From source file:com.kubotaku.android.openweathermap.lib.util.GeocodeUtil.java
/** * Get location address from target location name. * <p/>//from w w w.j av a2 s.co m * Use Android Geocode class. * <p/> * * @param context Context. * @param locale Locale. * @param name Location name. * @return Location address. */ @Deprecated public static LatLng nameToPoint(final Context context, final Locale locale, final String name) { LatLng address = null; try { Geocoder geocoder = new Geocoder(context, locale); List<Address> addressList = null; try { addressList = geocoder.getFromLocationName(name, 1); } catch (IOException e) { e.printStackTrace(); } if ((addressList != null) && !addressList.isEmpty()) { for (Address point : addressList) { double latitude = point.getLatitude(); double longitude = point.getLongitude(); address = new LatLng(latitude, longitude); } } } catch (Exception e) { e.printStackTrace(); } return address; }
From source file:fr.gotorennes.AbstractMapActivity.java
public static Location getLocation(Context context, String address) { if ("".equals(address.trim())) { android.location.Location l = LocationUtils.getLocation(context); return l != null ? new Location(l.getLatitude(), l.getLongitude(), context.getString(R.string.positionActuelle)) : null;//from w w w . jav a2s . c om } Geocoder geocoder = new Geocoder(context); try { List<Address> addresses = geocoder.getFromLocationName(address + ",35 ille et vilaine", 1); if (addresses != null && !addresses.isEmpty()) { Address foundAddress = addresses.get(0); return new Location(foundAddress.getLatitude(), foundAddress.getLongitude(), foundAddress.getAddressLine(0)); } } catch (Exception ex) { Log.e("GoToRennes", ex.getMessage()); } return null; }
From source file:com.binomed.showtime.android.util.CineShowtimeRequestManage.java
private static Location manageLocation(Geocoder geocoder, String cityName, URLBuilder andShowtimeUriBuilder, Double latitude, Double longitude) throws IOException { Location originalPlace = null; if (geocoder != null) { if (cityName != null) { try { cityName = URLDecoder.decode(cityName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "Error during encode", e); }//from ww w . ja v a 2 s. c o m List<Address> addressList = geocoder.getFromLocationName(cityName, 1); if ((addressList != null) && !addressList.isEmpty()) { if (addressList.get(0).getLocality() != null) { cityName = addressList.get(0).getLocality(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getPostalCode() != null)) { cityName += " " + addressList.get(0).getPostalCode(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getCountryCode() != null)) { cityName += ", " + addressList.get(0).getCountryCode(); } originalPlace = new Location("GPS"); originalPlace.setLongitude(addressList.get(0).getLongitude()); originalPlace.setLatitude(addressList.get(0).getLatitude()); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } if ((latitude != null) && (longitude != null) && ((latitude != 0) && (longitude != 0))) { List<Address> addressList = geocoder.getFromLocation(longitude, latitude, 1); if ((addressList != null) && !addressList.isEmpty()) { if (addressList.get(0).getLocality() != null) { cityName = addressList.get(0).getLocality(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getPostalCode() != null)) { cityName += " " + addressList.get(0).getPostalCode(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getCountryCode() != null)) { cityName += ", " + addressList.get(0).getCountryCode(); } originalPlace = new Location("GPS"); originalPlace.setLongitude(addressList.get(0).getLongitude()); originalPlace.setLatitude(addressList.get(0).getLatitude()); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LAT // , AndShowtimeNumberFormat.getFormatGeoCoord().format(latitude)); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LONG// , AndShowtimeNumberFormat.getFormatGeoCoord().format(longitude)); } } else { if (cityName != null) { try { cityName = URLDecoder.decode(cityName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "error during decoding", e); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } if ((latitude != null) && (longitude != null) && ((latitude != 0) && (longitude != 0))) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LAT // , AndShowtimeNumberFormat.getFormatGeoCoord().format(latitude)); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LONG// , AndShowtimeNumberFormat.getFormatGeoCoord().format(longitude)); } } return originalPlace; }
From source file:com.binomed.showtime.android.util.CineShowtimeRequestManage.java
public static NearResp searchTheatersOrMovies(Context context, Double latitude, Double longitude, String cityName, String movieName, String theaterId, int day, int start, String origin, String hourLocalized, String minutesLocalized) throws Exception { URLBuilder andShowtimeUriBuilder = new URLBuilder(CineShowTimeEncodingUtil.convertLocaleToEncoding()); andShowtimeUriBuilder.setProtocol(HttpParamsCst.BINOMED_APP_PROTOCOL); andShowtimeUriBuilder.setAdress(getAppEngineUrl(context)); andShowtimeUriBuilder.completePath(HttpParamsCst.BINOMED_APP_PATH); andShowtimeUriBuilder/* ww w.ja v a 2s .c o m*/ .completePath(((movieName != null) && (movieName.length() > 0)) ? HttpParamsCst.MOVIE_GET_METHODE : HttpParamsCst.NEAR_GET_METHODE); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LANG, Locale.getDefault().getLanguage()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_OUTPUT, HttpParamsCst.VALUE_XML); // andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_ZIP, HttpParamsCst.VALUE_TRUE); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_IE, CineShowTimeEncodingUtil.getEncoding()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_OE, CineShowTimeEncodingUtil.getEncoding()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_CURENT_TIME, String.valueOf(Calendar.getInstance().getTimeInMillis())); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_TIME_ZONE, TimeZone.getDefault().getID()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_HOUR_LOCALIZE, hourLocalized); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_MIN_LOCALIZE, minutesLocalized); if (theaterId != null) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_THEATER_ID // , theaterId); } if (day > 0) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_DAY // , String.valueOf(day)); } if (start > 0) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_START // , String.valueOf(start)); } String countryCode = Locale.getDefault().getCountry(); Geocoder geocoder = CineShowtimeFactory.getGeocoder(); Location originalPlace = null; if (geocoder != null) { if (cityName != null) { try { cityName = URLDecoder.decode(cityName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "error during decoding", e); } List<Address> addressList = null; try { addressList = geocoder.getFromLocationName(cityName, 1); } catch (Exception e) { Log.e(TAG, "error Searching cityName :" + cityName, e); } if ((addressList != null) && !addressList.isEmpty()) { if (addressList.get(0).getLocality() != null) { cityName = addressList.get(0).getLocality(); } // if (addressList.get(0).getLocality() != null && // addressList.get(0).getPostalCode() != null) { // cityName += " " + addressList.get(0).getPostalCode(); // } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getCountryCode() != null)) { cityName += ", " + addressList.get(0).getCountryCode(); } originalPlace = new Location("GPS"); originalPlace.setLongitude(addressList.get(0).getLongitude()); originalPlace.setLatitude(addressList.get(0).getLatitude()); countryCode = addressList.get(0).getCountryCode(); } if (cityName != null) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } } if ((latitude != null) && (longitude != null) && ((latitude != 0) && (longitude != 0))) { List<Address> addressList = null; try { addressList = geocoder.getFromLocation(latitude, longitude, 1); } catch (Exception e) { Log.e(TAG, "error Searching latitude, longitude :" + latitude + "," + longitude, e); } if ((addressList != null) && !addressList.isEmpty()) { if (addressList.get(0).getLocality() != null) { cityName = addressList.get(0).getLocality(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getPostalCode() != null)) { cityName += " " + addressList.get(0).getPostalCode(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getCountryCode() != null)) { cityName += ", " + addressList.get(0).getCountryCode(); } originalPlace = new Location("GPS"); originalPlace.setLongitude(addressList.get(0).getLongitude()); originalPlace.setLatitude(addressList.get(0).getLatitude()); countryCode = addressList.get(0).getCountryCode(); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LAT // , AndShowtimeNumberFormat.getFormatGeoCoord().format(latitude)); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LONG// , AndShowtimeNumberFormat.getFormatGeoCoord().format(longitude)); if (cityName != null) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } } } else { if (cityName != null) { try { cityName = URLDecoder.decode(cityName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "error during decoding", e); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } if ((latitude != null) && (longitude != null) && ((latitude != 0) && (longitude != 0))) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LAT // , AndShowtimeNumberFormat.getFormatGeoCoord().format(latitude)); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LONG// , AndShowtimeNumberFormat.getFormatGeoCoord().format(longitude)); } } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_COUNTRY_CODE, countryCode); if (movieName != null) { try { movieName = URLDecoder.decode(movieName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "error during decoding", e); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_MOVIE_NAME, movieName); } String uri = andShowtimeUriBuilder.toUri(); Log.i(TAG, "send request : " + uri); //$NON-NLS-1$ HttpGet getMethod = CineShowtimeFactory.getHttpGet(); getMethod.setURI(new URI(uri)); HttpResponse res = CineShowtimeFactory.getHttpClient().execute(getMethod); XMLReader reader = CineShowtimeFactory.getXmlReader(); ParserNearResultXml parser = CineShowtimeFactory.getParserNearResultXml(); reader.setContentHandler(parser); InputSource inputSource = CineShowtimeFactory.getInputSource(); // inputSource.setByteStream(new GZIPInputStream(res.getEntity().getContent())); inputSource.setByteStream(res.getEntity().getContent()); reader.parse(inputSource); NearResp resultBean = parser.getNearRespBean(); resultBean.setCityName(cityName); return resultBean; }
From source file:com.sahana.geosmser.view.ReverseGeocoderView.java
public GeoPoint getGeoByDefaultAddress(String searchAddress) { GeoPoint mGeoPoint = null;/* w w w . j a va 2s. c o m*/ try { if (!searchAddress.equals("")) { Geocoder mGeocoder = new Geocoder(mContext, Locale.getDefault()); List<Address> mAddressList = mGeocoder.getFromLocationName(searchAddress, 1); if (!mAddressList.isEmpty()) { Address mAddress = mAddressList.get(0); double mLatitude = mAddress.getLatitude() * 1E6; double mLongitude = mAddress.getLongitude() * 1E6; mGeoPoint = new GeoPoint((int) mLatitude, (int) mLongitude); } else { Log.d(WhereToMeet.TAG, "Address Not Found!"); } } } catch (Exception e) { Log.d(com.sahana.geosmser.WhereToMeet.TAG, e.getMessage()); } return mGeoPoint; }
From source file:kien.activities.DistrictAcitivity.java
public LatLng getLocationFromAdress(String strAddress) { Geocoder geocoder = new Geocoder(this); List<Address> addresses; LatLng lng = new LatLng(0, 0); Log.e("LATLONG", "hello"); try {/*from w w w. j a v a2 s .co m*/ addresses = geocoder.getFromLocationName(strAddress, 5); Log.e("LATLONG", strAddress + ""); if (addresses == null) { return null; } Address location = addresses.get(0); location.getLatitude(); location.getLongitude(); Log.e("LATLONG", location.getLatitude() + " " + location.getLongitude()); lng = new LatLng(location.getLatitude(), location.getLongitude()); } catch (IOException e) { Log.e("LATLONG", strAddress + " error"); e.printStackTrace(); } return lng; }
From source file:com.example.aula20141117.util.AmUtil.java
public LatLng getLatLongFromString(String address, Activity calling) { LatLng ret = null;/*from www . j av a 2 s . com*/ double lat = 0.0, lng = 0.0; Geocoder geoCoder = new Geocoder(calling, Locale.getDefault()); try { List<Address> addresses = geoCoder.getFromLocationName(address, 1); if (addresses.size() > 0) { GeoPoint p = new GeoPoint((int) (addresses.get(0).getLatitude() * 1E6), (int) (addresses.get(0).getLongitude() * 1E6)); lat = p.getLatitudeE6() / 1E6; lng = p.getLongitudeE6() / 1E6; Log.d("Latitude", "" + lat); Log.d("Longitude", "" + lng); ret = new LatLng(lat, lng); } } catch (Exception e) { e.printStackTrace(); } return ret; }
From source file:com.capstone.transit.trans_it.TripDisplayActivity.java
public double[] getFromLocation(String address) { double[] Coordinates = new double[2]; Geocoder geoCoder = new Geocoder(this, Locale.getDefault()); try {//from w w w . j a va 2 s . c o m Address addressConvert = geoCoder.getFromLocationName(address, 1).get(0); Coordinates[0] = addressConvert.getLatitude(); Coordinates[1] = addressConvert.getLongitude(); } catch (Exception ee) { } return Coordinates; }