Reputation: 1570
I'm building a php based application for a client to enter in addresses for their customers' buildings. They'd like the ability to view the location on a map (either as individuals or grouped in a city search).
What I'm trying to accomplish is a lookup once the address is entered into a form that populates the database, so after they enter in the addresss, city, state, zip (these are all US locations) they could click a "get lat/long info" link/button that would check to make sure the data is complete, then would lookup the address and return the latitude/longitude into the appropriate form fields. Then the form could be submitted to store the info, and I could later just pull the lat/long when plotting on a map.
Does this make sense, or would I be better off just doing the lookup when it's time to plot it?
Does anyone have any pointers to solve this problem?
I've seen some of the Google/Yahoo API's but it looks like this is more based on the plotting a point part. I may be able to modify it to suit my needs, but I'm just trying to cut some research time posting here with the hopes one of you may have a more direct route.
I'll RTM if I have to...
Upvotes: 3
Views: 3604
Reputation: 50710
What you're looking for is referred to as geocoding; check out Google's Geocoding web service:
Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map.
The Google Maps API Geocoding Service provides a direct way to access a geocoder via an HTTP request. Additionally, the service allows you to perform the converse operation (turning coordinates into addresses); this process is known as "reverse geocoding."
Your approach to the problem makes sense, although I'm not sure how much validation a geocoding result actually provides (unless you're showing your users the resulting plot on a map).
Upvotes: 2
Reputation: 3738
A quick Google search for PHP geocoding returned this: http://code.google.com/apis/maps/articles/phpsqlgeocode.html. You may have to tailor it a bit to your needs, but that should definitely get you going.
Upvotes: 0