caipivara
3/21/2015 - 12:40 PM

Get location by address - Google Maps V2 Android

Get location by address - Google Maps V2 Android

public class LocationHelper {

  public static LatLng getLocationFromAddress(String strAddress) {
	LatLng latLng = null;
	Geocoder coder = new Geocoder(App.getInstance().getApplicationContext());

	try {
	  ArrayList<Address> addresses = (ArrayList<Address>) coder.getFromLocationName(strAddress, 1);

	  //TODO: Implement Controls to ensure it is right address such as country etc.
	  double longitude = addresses.get(0).getLongitude();
	  double latitude = addresses.get(0).getLatitude();

	  latLng = new LatLng(latitude, longitude);

	} catch (IOException e) {
	  Timber.e("getLocationFromAddress", e);
	}

	return latLng;
  }
}