Aswin Balaji

Aswin Balaji

186 Sadasivam Nagar,Madipakkam,Chennai, TN 600091
Aswin Balaji

Latitude,Longitude and Address Using Android

September 14, 2015, by Aswin Balaji, category ANDROID
We get location and latitude using LocationManager Class in android. We can get address using Latitude and Longitude.

AndroidCode
private String getName(String lat,String lng) throws IOException
{
String add=””;
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try
{
List addresses = geocoder.getFromLocation(lat, lng, 1);Address obj = addresses.get(0);
add = obj.getAddressLine(0) +” “+obj.getAddressLine(1)+” ”                                                          + obj.getAddressLine(2);
}
catch(Exception ex)
{
Toast.makeText(this,”exception”+ex.getMessage(),Toast.LENGTH_LONG).show();
}
return add;
}
How do I get the latitude and longitude of an address using the Google Maps API?

public GeoPoint getLocationFromAddress(String strAddress){    Geocoder coder = new Geocoder(this);  List<Address> address;  GeoPoint p1 = null;    try {      address = coder.getFromLocationName(strAddress,5);      if (address == null) {          return null;      }      Address location = address.get(0);      location.getLatitude();      location.getLongitude();        p1 = new GeoPoint((int) (location.getLatitude() * 1E6),                        (int) (location.getLongitude() * 1E6));        return p1;  }
strAddress is a string containing the address. The address variable holds the converted addresses.