Question

I am looking for any web api that will allow me to find the county I am located in, given a set of lat/long. I know that it can be done via the Android GeoCoder, but I was not satisfied with the results, even from my home location, located in a city, the location returned null, using the following code:

addresses = geocoder.getFromLocation(mLocation.getLatitude(), mLocation.getLongitude(), 1);
address=addresses.get(0);
Log.v(TAG,""+address.getSubAdminArea());

It found my address, my state, and my city, but not my county.

Ultimately, I want this to work in a situation where I could be far away from a paved road, but still know what county I'm in, and I'm convinced that if I can't even figure out where I am in a city, I'm never going to figure out where I am in a country setting. I would prefer not to pay for this service, but I'm even willing to pay if the service is good enough. I want to use a web api, and I will accept obviously that I need internet access in said remote location.

The perfect application would meet the following requirements, in order of priority.

  1. Work in any location, very reliably, with no roads required
  2. Function in the United States.
  3. Work in any country, with their equivalent of a county, prioritized by technical use.
  4. Work quickly
  5. Be able to make ~ 1000 calls minimum per day free of charge.
  6. Also pull state information, and zip code.
  7. Work even on small uninhabited islands, assuming internet access of course.
Was it helpful?

Solution 2

You can give Nominatim a try. It should meet all of your requirements. It uses data from OpenStreetMap and is capable of geocoding and reverse-geocoding. See this example reverse-geocoding query:

http://nominatim.openstreetmap.org/reverse?format=xml&lat=52.5487429714954&lon=-1.81602098644987&zoom=18&addressdetails=1

It can also return JSON instead of XML if you modify the format parameter.

OSM's official Nominatim instance has a rather strict usage policy because it runs on donated servers. But there are alternative instances without such limits, for example the one provided by MapQuest. And of course a local installation is possible, too.

OTHER TIPS

I am not sure whether Android GeoCoder uses Google GeoCoding api, but I just tested this API with my address, and it returns the address including a county-like one.

Can you try this with your address?

http://maps.googleapis.com/maps/api/geocode/json?latlng=37.6,125.961452&sensor=true

Reference:

https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding https://developers.google.com/maps/documentation/geocoding/#Types

I've found that a combine approach seems to be best to managing both the accuracy, and the API calls. I've been doing a bit of work, and so far am using the following 4 services, in order:

  1. Android's Geocoder
  2. http://developer.mapquest.com/
  3. https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding
  4. http://www.geonames.org/maps/us-reverse-geocoder.html#findNearestAddress

Still working on others, but these seem to work for all of the typical addresses I've entered so far.

Of these, Map Quest seems to work the best overall, it will figure out what zip code an area is in, which will find the county as well. Overall I'm pleased with it. Google Maps API failed the Virginia Independent Cities, such as http://maps.googleapis.com/maps/api/geocode/json?latlng=38.7451,-77.478876&sensor=false , but I was able to make it work via a bit of extra code. The GeoNames did do Virginia Independent Cities. In fact, GeoNames seems to be the overall winner, except it doesn't work outside of the US and doesn't work as well as the fringe cases.

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