How to Create Google Maps Awesomeness in 5 Minutes Flat
Posted by Pete - 26/08/08 at 10:08:46 amHere’s something a bit different from me today. After my last post, it looked like some people either weren’t sure what you could use the Google Maps paramaters for, or wanted to know how to generate simple Google Maps. So I thought I’d lend a hand.
First, you’re going to need to sign up for a Google Maps API key. Next, you’re probably going to want to get the location of a search input. To do that, we’re going to want to generate some XML, and that’s where this little beauty comes in handy:
$location = str_replace(‘ ‘, ‘+’, $searchterm);
// Desired address
$address = “http://maps.google.com/maps/geo?q=$location&output=xml&key=GOOGLE+MAPS+API+KEY+HERE&oe=utf8″;
// Retrieve the URL contents
$page = file_get_contents($address);
// Parse the returned XML file
$xml = new SimpleXMLElement($page);
?>
$searchterm - the place the user is looking for
$location - the tweaked version, used by the API
What this does it take the search term, and generate the XML data for that particular place. This tends to work best in my experience, if you feed in data in the form of “city/town/villiage, country”, although it also works for postcodes, places of interest (such as the Great Wall of China), and pretty much anything else you can imagine.
Once you’ve got that, you can then generate a map with it. For tutorials on how to do that, as well as how to add markers, lines, and just about anything else, I’d recommend checking out Mike Williams’ site, as it’s way better than most of the Google documentation.
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
You must be logged in to post a comment.




