views:

71

answers:

1

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.

+2  A: 

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.

Scythe
Do I need any API keys etc to use the Geocoder class? I think for my requirement I can even use the cell information actually since I just need the city name not even the sublocality for now. Thanks for the link and info Scythe !!
Aakash
No, I'm quite sure that you don't need an API key for that. Here's a related question, there's an example in the thread that you can try out http://stackoverflow.com/questions/472313/android-reverse-geocoding-getfromlocation Don't forget to request the INTERNET permission for your app (I always forget :) ).
Scythe
What I found using the LocationManager NETWORK_PROVIDER is that the address returned from the Lat Long info is often null.
Aakash