Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find County name for a Lat/Long

I'm trying to find a webservice that will allow me to get a County name (not Country) for a specific Lat/Long. I would be performing the lookup within a server application (likely a Java application). It doesn't have a be a webservice if there is some library out there I suppose, but I would like up-to-date information. I have looked around quite a bit for an API that supports this, but so far I haven't been able to find one that works. I have tried the Yahoo APIs like so:

http://where.yahooapis.com/geocode?q=39.76144296429947,%20-104.8011589050293

But it doesn't populate the address information. I've tried with some of the "flags" options there too to no avail.

I've also looked around at Googles APIs as well, but I've read multiple places that they don't populate the County.

So does anyone know of any APIs that will take a Lat/Long and return the County associated with that location? And if you have any examples, that would be great.

I'd also like to know which APIs allow for use in a commercial application. A lot of the data I've found says that you can't use the data to make money. I might be reading those wrong, but I'm looking to build a service that I'd likely charge for that would use this data. So I'd need options. Maybe free services while I'm exploring options, and pay services down the road.

like image 783
Andrew Serff Avatar asked May 03 '11 02:05

Andrew Serff


People also ask

How do I find a place using longitude?

To find a location using its latitude and longitude on any device, just open Google Maps. On your phone or tablet, start the Google Maps app. On a computer, go to Google Maps in a browser. Then enter the latitude and longitude values in the search field — the same one you would ordinarily use to enter an address.

How do I find the nearest city to lat long?

Download the cities database from http://download.geonames.org/export/dump/ Add each city as a lat/long -> City mapping to a spatial index such as an R-Tree (some DBs also have the functionality) Use nearest-neighbour search to find the closest city for any given point.


Video Answer


2 Answers

Just for completeness, I found another API to get this data that is quite simple, so I thought I'd share.

https://geo.fcc.gov/api/census/

The FCC provides an Block API for exactly this problem and it uses census data to perform the look up.

Their usage limit policy is (From [email protected])

We do not have any usage limits for the block conversion API, but we do ask that you try to spread out your requests over time if you can.

like image 150
Andrew Serff Avatar answered Sep 25 '22 14:09

Andrew Serff


Google does populate the county for your example,

http://maps.googleapis.com/maps/api/geocode/json?latlng=39.76144296429947,-104.8011589050293&sensor=false

In the response, look under the key address_components which contains this object representing "Adams" county,

{
    long_name: "Adams"
    short_name: "Adams"
    -types: [
        "administrative_area_level_2"
        "political"
    ]
}

Here's from the Geocoding API's docs,

administrative_area_level_2 indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.

like image 42
Anurag Avatar answered Sep 25 '22 14:09

Anurag