-3

I`m Trying to get city name in an application. Just like if the GPS shows New York so the place should set inside an text view as new York and if the GPS shows location as India so the text view should show as India

1 Answers1

0

Try this code:

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

addresses = geocoder.getFromLocation(latitude, longitude, 1); 

String city = addresses.get(0).getLocality();
Manish
  • 353
  • 2
  • 18
  • Just i need to add this code? or something else i need to add? – Ashwani Sharma Jul 15 '16 at 12:49
  • first of all get lat long from GPS then add this code – Manish Jul 15 '16 at 12:49
  • because you need lat long first – Manish Jul 15 '16 at 12:50
  • follow this link to get lat long http://stackoverflow.com/questions/36622586/show-my-current-location-in-the-google-map/36623078#36623078 – Manish Jul 15 '16 at 12:53
  • you havent understand my question.. i dont want to open map... Just like an fake gps we can set fake location through an app.. so if we set india from that app so that in my application if i search for it then it should automatically fetch india from that – Ashwani Sharma Jul 15 '16 at 13:04