Question

I am trying to determine the city in USA the user is in using their current location from an Android App. I want to use the GPS as the location provider but how accurately can I determine the name of the city from the Locale or Latitude / Longitude data.

For instance I noticed the twitter app determines you are in Manhattan when tweeting from Manhattan, but is it possible to retrieve New York City instead of Manhattan from the location data and likewise Los Angeles instead of Beverly Hills.

This is because all I need to determine is which city the user is in as per the current location.

Thanks for all the help.

Was it helpful?

Solution

You need the Geocoder class for that. See the reference, it's quite easy to use: http://developer.android.com/reference/android/location/Geocoder.html . The process you're mentioning is called reverse geocoding. I think it's quite accurate (especially if only the city name is needed), I've used it in some of my projects.

But if you only want to determine the city the user's currently in, it might be enough to use the cell information for that, rather then the gps provider. For the gps to work, the user has to be outside, the provider based on cell info works quite well inside buildings too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top