Just about everyone in today’s internet has either a Google, Bing or MapQuest map on their web page, and although this is a fine idea there have been several times when I want to know how to get there from where I live, work, or eat. You are left with a couple of choices, you could try and copy and paste to Google map and then add a destination or you could zoom out and try and figure it out yourself. Why not add the ability for a user to enter in their address and then let them see driving directions from your site. Furthermore; if you wanted to capture the address that they are using you might find a pattern which might help target your advertising dollar. This article will walk you through the steps to add this to your site. Trust me it is not very difficult.
Before we get started let me mention that we are going to use a jQuery Google library called Gmap3. This script is great to use because it makes coding and configuration a lot easier than trying to read Google’s API maps directly. This also works very nicely if you are already using jQuery in your web site. I had built a web site using version 3 but in writing this article I had to make some code changes because of Version 5.
Note: I have added the whole script to one page. If you are going to use it I would suggest that you follow best practices by splitting it up (Javasripts, CSS, and HTML all separate).
Here we go…..
Create a blank html page and replace this code with the page.
That’s it! (Simple isn’t it).
A couple of things to notice in this page.
- The Google Map API does not contain a API Key. (You might want to use one anyway. You will get more statistics if you do)
- I am using addresses but you could easily change to Geocoding the addresses. (If you are using a database to look at areas where people are mapping to then geocoding is a little easier to use)
Let me know what you think and by the way head over to Arvixe and check out their hosting options.
Looking for quality web hosting? Look no further than Arvixe Web Hosting!