> Andy’s Blog

2 min read

HTML5 Geolocation, Macs and an interesting realisation 🗺

Geofencing is “the use of GPS or RFID technology to create a virtual geographic boundary, enabling software to trigger a response when a mobile device enters or leaves a particular area.” (thanks Wikipedia).

There are several applications for this. One that is used by Uber is to manage pickups from LAX. As Uber is prohibited from using LAX’s private hire car/taxi pick up and drop off zone, Uber has created a geofenced area nearby (see below) where drivers (once they are within the area) can wait for a fare from LAX, then pick up individuals from the regular pick up area at the airport.

A map of Ubers geofenced waiting area

Native apps have supported this kind of functionality for a while, due to their ability to interface directly with GPS location data from the users mobile device. However websites and web-apps have only been able to access this data since the advent of HTML5 through the Geolocation API.

When a website requests your geolocation, the browser will prompt you to give permission to provide them with your location. When you agree the browser then requests your location coordinates from your device.

While I was playing with the geolocation api on the W3 website, I notice that my location was very accurate. This surprised me as I was using my laptop. I had assumed that the location for a laptop would be determined by my IP address. Mac’s don’t have GPS’s so I went down a mini rabbit hole trying to figure out what was going on. First I turned on my VPN, set the location to London then refreshed the page. The location was still showing my home address so I could confirm that it definitely wasn’t going off the IP address. Then I turned off my mobile phone. I thought that my iPhone might be sharing my location data with my Mac, but even after turning that off it was still showing my home address. I then had a bit of a dig around online and found this post.

It turns out that through a process called trilateration*. My Mac gathers as much data as it can from the wifi networks within range (including signal strength) and looks up those addresses in Apples database of geolocated wifi enabled devices. Based off this calculation it determines my address within an uncomfortable level of accuracy.

This has certainly made me a lot more wary of how accurate my location data is on my laptop… so I think I’ll go back to disabling my location services for now!

*Similar to triangulation, trilateration relies on signal strength rather than response time differences to calculate a location.


Andy Brown

Thanks for dropping by. Iʼm a web developer from Sydney, Australia. I hope whatʼs written here has either taught you something, given you some inspiration or provided you with a bit of entertainment.

Feel free to connect with me on LinkedIn.