Geocoding:
Geocoding is the process of converting the addresses (postal address) into geo coordinates as latitude and longitude.Reverse geocoding is converting a geo coordinate latitude and longitude to an address.
In this tutorial we will be doing reverse geo coding and get the addresses of the passed coordinates
Step 1
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
To Achieve Geocode, use the below code
Geocoder gc = new Geocoder(context);
if(gc.isPresent()){
List<Address> list = gc.getFromLocationName(“155 Park Theater, Palo Alto, CA”, 1);
Address address = list.get(0);
double lat = address.getLatitude();
double lng = address.getLongitude();
}
To Achieve Reverse Geocode, use the below code
Geocoder gc = new Geocoder(context);
if(gc.isPresent()){
List<address> list = gc.getFromLocation(37.42279, -122.08506,1);
Address address = list.get(0);
StringBuffer str = new StringBuffer();
str.append(“Name: ” + address.getLocality() + “\n”);
str.append(“Sub-Admin Ares: ” + address.getSubAdminArea() + “\n”);
str.append(“Admin Area: ” + address.getAdminArea() + “\n”);
str.append(“Country: ” + address.getCountryName() + “\n”);
str.append(“Country Code: ” + address.getCountryCode() + “\n”);
String strAddress = str.toString();
}
No comments:
Post a Comment