Using GPS - Part 2 (Web Design)
Posted by Charlie Recksieck
Employing Geolocation On Your Website
* * *
This article should still be of interest to you, even if you don't write code for websites. We want to take a look at the methods a website has to see where you physically are.
Why Put Location/GPS Tools On Your Site
Obviously, if you are providing any map-based services on your site, you'll want location tools on your website. But even if not providing a dynamic, real-time map, a website having a loose idea of where you are can be a good idea for them AND you. Right away, knowing the country can guide the language and content of the site. Knowing your city means that any advertising could be localized and the content as well.
We have done music websites for bands and labels. If one of these bands has an upcoming tour, the site's code could start by seeing if the website visitor is in an area where they will have a show and if so then put that info up top at the front of the site. (Believe me, putting potentially relevant info up front and not relying on users searching and scrolling is more crucial than you'd even expect.)
What Websites Know About You
There are two primary ways where websites can tell your location: "Geolocation" (the more accurate one) and your IP address location.
As one would imagine, when you're on a cellphone, that more precise location is the Geolocation method - and it's possible on laptops and desktops too when access is granted. On mobile or non-mobile, you always have the option to protect your privacy and turn off location services in a browser.
But that doesn't mean they don't have any idea where you are. Whenever you are using wifi, the connection point like your modem has an IP address (e.g. 220.127.116.11). Your general location can be looked up, even if you turn these services off.
(Note for privacy buffs: If you really, really want to be more anonymous on the web, you can use VPNs "Virtual Private Networks" to fake where you are.
Coding A Website For GPS Location
Since users (rightly) have the prerogative of not supplying sites with specific accuracy and rejecting the location-sharing option (whether on their phone or in the settings for a laptop/desktop browser), then designers should take a two-tiered approach:
1) If site can read the geolocation HTML5 object, then do that.
2) If site cannot read via geolocation functions, THEN read the IP address and get more generalized location info from there.
Click to enlarge
First click "Get GPS" button. Once complete, click "Lookup Info" button.
First of all, there are LOTS of free geolocation services and sites. Unless your site is making thousands of location requests per day, you should be able to get all of this done with free services. Caveat emptor: Sometimes these services do disappear, change their format or something else overnight which would momentarily break your code depending on them. But if you find a good one, go ahead and rely on it. Should the service change in the future, it's easy enough to correct and find a different one.
The quality of location info varies to an almost insane degree. I'm going to list these free GPS info services in increasing order of accuracy and usefulness. The first ones really are quite generic. Please check these out
Again, the first couple of these results placed me over 100 miles from my real location, whereas the last couple were accurate. As one would expect, services that take latitude and longitude as a supplied argument will be more accurate.
All of these are free and there are many more free and paid services out there for you.
Here’s an example of how the data comes back from one of these sites as JSON object.
How accurate are GPS readings on this more precise geolocation? It depends on the service. Paid services can be accurate up to 3 meters. The free ones I’ve played with can be off by a house or two (about 30 meters)
How accurate are GPS readings on non-geolocation? Again, it varies. Between a couple of IP located services I've used, one showed my IP address in Los Angeles where in reality I live and work in San Diego. And another free service showed a location value of a neighborhood that is less than 5 miles away from my house, instead of the 120 miles away of the Los Angeles location.
For a real-world example, when I go to the Target store website, it’s clearly using the more generic IP locator since it tries to set my default store location to something in the Valley in L.A. - which is a two-hour drive from me.
So, which service you use really matters.
As a user, remember that just because you've turned off location services that doesn't mean that we don't know what neighborhood you're in - we just don't know your street. Also, it's not that nefarious - companies have very good reasons for trying to localize your content and improve your user experience.
As an owner of a business or website, it's really not hard to take advantage of geolocation on your website. Get creative for its best uses in your business. If you want to use this, there's no excuse for not doing it. Most of these good free webs APIs I've shown above allow up to thousands of requests per day before requiring a paid account.
We tried to keep the code and examples here fairly simple. Should you want some more help, feel free to reach out to us for our free two cents. We'd love to be of assistance.