Zeeshan Ahmed
Zeeshan Ahmed

Reputation: 1187

how to show the street name, postcode/zip-code, city automatically of the current location using maps api v2

I'm a Beginner in android development. I'm using Google Maps API V2 in my Application. I want to show the street name, postcode/zip-code, city automatically of the current location. Currently I'm just displaying the longitude and latitude of the current location but don't know how to get this information as well. Can Anyone please tell me the right way, that how can I get these information(street name, postcode/zipcode, city) from the maps api v2..

Upvotes: 0

Views: 5200

Answers (2)

GrIsHu
GrIsHu

Reputation: 23638

Geocoding is the process of finding the geographical coordinates (latitude and longitude) of given address or location.

Reverse Geocoding as you might have guessed is the opposite if Geocoding. In this case a pair of latitude and longitude is converted into an address or location.

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);

String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);

Upvotes: 2

Sino
Sino

Reputation: 886

Please refer this link-http://developer.android.com/reference/android/location/Geocoder.html

Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address. The amount of detail in a reverse geocoded location description may vary, for example one might contain the full street address of the closest building, while another might contain only a city name and postal code. The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.

Example:-

   Geocoder geoCoder = new Geocoder(context);

   List<Address> matches = geoCoder.getFromLocation(latitude, longitude, 1);

   Address bestMatch = (matches.isEmpty() ? null : matches.get(0));

give your current location coordinates to the function geoCoder.getFromLocation() and find the address details.

Upvotes: 2

Related Questions