4

I have a set of 900 Latitude and Longitude Coordinates-- I need a relatively simple method for finding the 'State' referred to by these coordinates. If it helps, the data is in excel.

Parseltongue
  • 9,008
  • 26
  • 78
  • 131
  • You could model the states as polygons on a sphere(i.e. Earth), and modify the [point in polygon algorithm](http://en.wikipedia.org/wiki/Point_in_polygon) to work on an ecliptic plane. Of course, that assumes you have lat/long data for each state's border. Or are you asking for like a public API that has already done the math for you? I wouldn't be surprised if Google Maps or something has a `whichStateAmIIn(lat, long)` method. – Kevin Jan 25 '13 at 21:28
  • 1
    The polygons of the US states are contained in the Wikipedia SVG file showing the US map: http://upload.wikimedia.org/wikipedia/commons/1/13/Map_of_USA_States_with_names_white.svg – Axel Kemper Jan 31 '13 at 22:51

4 Answers4

5

Google provide a Geocoding service. Part of this is reverse geocoding which converts geographic coordinates into a human-readable address including States. This Demo illustrates what can be done. There are limits to what you can do with this service.

david strachan
  • 6,992
  • 2
  • 21
  • 33
  • As stated by user1473461, Google requires that you show a visible Google map when using their Geocoding API. "The Google Maps Geocoding API may only be used in conjunction with displaying results on a Google map. It is prohibited to use Google Maps Geocoding API data without displaying a Google map." https://developers.google.com/maps/documentation/geocoding/policies – Sean Michaud Apr 10 '18 at 18:59
2

Try to use the average values as provided here. With a bit of luck, most of your 900 coordinate pairs belong to the state with the nearest center. Calculation of distances between longitude/latitude locations is explained here.

An alternative would be to use a ZIP table with US postcodes as provided here. Once you know the postcode, you know the state, don't you? I'm not sure, but each state has an interval of ZIP codes. Once you know the ZIP code of a location, you can find the interval and the state it belongs to.

A list of coordinates of US locations could help to get a more exact allocation: http://www.bcca.org/bahaivision/fast/latlong_us.html Find the nearest location in the list and take its state as result.

Community
  • 1
  • 1
Axel Kemper
  • 7,949
  • 2
  • 24
  • 47
2

Google requires that geocoding / reverse geocoding be used with maps that users can see, so if that isn't an option for you, I think the best way is to use a database with spatial functions. First, you'll need the state boundaries found for free at NationalAtlas.gov. I use SQL Server (need 2008 or 2012 versions) and you can use the STContains() method to find what state it belongs to.

user1473461
  • 371
  • 2
  • 2
0

A simpler solution would be to just use the ezcmd.com rest API services. They provide two APIs:

http://ezcmd.com/apps/app_geo_postal_codes#geo_postal_codes_api

1) All you have to do is just give it a zip code and a country code (for usa you either use US or USA) and optionally you'll pass the distance radius, and units (Miles or Km) and it'll return all other zip codes with state and province that are within the given distance

2) Free search, where you give it any fuzzy search phrase that includes either one of zip / city / state / province and country and it returns the best matches for that search phrase.

Hint: You can use #2 to find the zip code for a fuzzy (human readable) address and pass that zip code to #1 to find nearest places to that zip code.

Also they have another API that returns zip code along with full geo location information for a given IP address here:

http://ezcmd.com/apps/app_ezip_locator#ezip_locator_api

Enjoy ! I hope this helps.