I’ve been having a lot of fun lately with Google maps, Google’s Directions API and HTML5’s geolocation feature. Together, these tools allow you to get your website visitor’s location and draw directions from their place to yours, all without leaving your website. Cool, huh?
As with anything on the web, there are a couple of caveats.
- When using HTML5 geolocation, the browser asks the website visitor whether they are willing to share their location via a pop-up box. Obviously, this can become annoying, so use geolocation sparingly on your site.
- Because website visitors can refuse to give their location, it’s a good idea to provide a form where those visitors can enter their address to get directions.
- Geolocation can give inaccurate results, particularly on desktop computers. It’s important to remember that geolocation is an estimate of your location. Your browser uses wireless access points, local network information and your IP address to figure out where you are. Typically, HTML5 geolocation works best on mobile devices. Since it’s likely that your customers will be looking for directions when they’re out on the road with their phones, you may want to use the HTML5 geolocation feature only on mobile optimized versions of your website. In any case, as noted above, it’s a good idea to provide a form where they can enter their address manually.
You can customize to fit your business requirements. If, for example, you have multiple locations, you could set up your locations page to find the location closest to your site visitor, and then give them directions to that location. Or you could let them choose the location, and then provide the directions.