Find the state given by latitude and longitude coordinates
Try using averages as indicated here . Luckily, most of your 900 coordinate pairs are in the nearest center state. This explains how to calculate the distances between longitude and latitude locations.
An alternative would be to use a ZIP table with US zip codes as noted here . Once you know the zip code, you know the state, right? I'm not sure, but every state has a zip interval. Once you know the zip code of a location, you can find the interval and state in which it belongs.
A list of coordinates for US locations can help you get a more accurate distribution: http://www.bcca.org/bahaivision/fast/latlong_us.html Find the nearest location in the list and get its state as a result.
source to share
Google requires geocoding / reverse geocoding to be used with maps that users can see, so if that's not an option for you, I think the best way is to use a database with spatial functionality. First, you need state borders found for free at NationalAtlas.gov. I am using SQL Server (needs 2008 or 2012 versions) and you can use the STContains () method to find which state it belongs to.
source to share
A simpler solution would be to just use the ezcmd.com service API. 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 the postcode and country code (for usa you are using the USA or the USA) and, if desired, you will walk the distance and unit radius (miles or km) and it's' return everything other zip codes with state and province within a 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 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 the nearest places for that zip code.
They also have another API that returns the zip code along with full geographic location information for a given IP address here:
http://ezcmd.com/apps/app_ezip_locator#ezip_locator_api
Enjoy! Hope this helps.
source to share
function getstate($lat, $long)
{
$json = json_decode(file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $long . '&sensor=false&key=google_api_key'), true);
$result = $json['results'][0];
foreach ($result as $key => $row) {
if ($key == 'address_components') {
for ($i = 0; $i < count($row); $i++) {
$k2 = $row[$i];
if ($k2['types'][0] == "administrative_area_level_1") {
$state = $row[$i]['long_name'];
return $state ;
}
}
}
}
}
source to share