0

I am new to android mobile development. I have used the Location Manager class and successfully found out the Longitude and the Latitude of the user. I want to use these values to find the city name. I don't want maps, I just want to get the city name. How do I do this?

Sindu_
  • 1,347
  • 8
  • 27
  • 67

3 Answers3

1

https://github.com/commonsguy/cw-lunchlist

https://github.com/commonsguy/cw-android

http://developer.android.com/reference/android/location/LocationManager.html

Have a look at these sites this will help you!!!!!1

Ghost
  • 3,966
  • 1
  • 25
  • 36
Thiru VT
  • 831
  • 2
  • 8
  • 24
  • 1
    No offense, but your links _don't really_ provide a solution as such. Please edit your answer. `Location Manager` is used to retrieve lat and long but the person isn't really asking about it. The question suggests that the answer is `Reverse Geo-coding` . Suggest you to edit your answer before you start getting negative votes.. – Ghost Jun 01 '12 at 12:34
1

First get Latitude and Longitude using Location and LocationManager class(That you have completed). Now try the code below for Get the city,address info

    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
    Geocoder gc = new Geocoder(this, Locale.getDefault());
    try {
    List<Address> addresses = gc.getFromLocation(lat, lng, 1);
    StringBuilder sb = new StringBuilder();
    if (addresses.size() > 0) {
    Address address = addresses.get(0);
    for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
    sb.append(address.getAddressLine(i)).append("\n");
    sb.append(address.getLocality()).append("\n");
    sb.append(address.getPostalCode()).append("\n");
    sb.append(address.getCountryName());

City info is now in sb. Now convert the sb to String (using sb.toString() ).

Antony
  • 603
  • 6
  • 14
1

You can use the Geocoder

Geocoder myLocation = new Geocoder(context, Locale.getDefault());
List<Address> myList = null;
try {
    myList = myLocation.getFromLocation(latitude, longitude, 1);
} catch (IOException e) {}

Where longitude and latitude are the valued retrieved by networks or GPS

znat
  • 13,144
  • 17
  • 71
  • 106