Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP - Get US State from Latitude & Longitude

Posted on 2011-09-08
2
Medium Priority
?
400 Views
Last Modified: 2012-05-12
I need a function that conceptually is very simple in PHP but seems pretty complex the more I think about it.

I need a PHP function to return the US State that a particular Latitude and Longitude is in. I have access to a database of points that represent the boundaries of the states and there might be 50 points or so per State.

Is there a straightforward way of doing this or could someone get me started with the function? We have a MySQL database that I'll be quering and I can certainly put the data into a Memory table, but this function will be run many times and so needs to be efficient.

If it were a simple square it'd be straightforward to me, but the crazy sizes of the states give me pause.

I'm also open if there is an existing script and/or product out there to achieve this as well.

Any ideas?

Thanks!
0
Comment
Question by:khilles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
dsacker earned 2000 total points
ID: 36504649
You may want to look into Google Geocoding API. For instance, there you can make a call for reverse address lookup (by longitude and latitude), as follows:
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false

Open in new window

It will return quite an XML descriptor.

Check out http://code.google.com/apis/maps/documentation/geocoding
0
 

Author Closing Comment

by:khilles
ID: 36506380
Thanks. Its not an ideal solution, but it'll work.

For those trying the same thing, what I'm going to do is first create a table (one row per State) turning the State into a rectangle with absolute largest Lat/Long and Smallest absolute Lat/Long this will handle 90% of the scenarios when there is only one state within that rectangle. When there's overlap, I'll use Google Maps to get the actual State.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question