Software Engineer

Geolocation on Page Load

· by Justin Zimmerman · Read in about 2 min · (220 Words)
Geolocation GeoIP

While building Geotinerary, I wanted the map to zoom relatively close to the users location. Surprisingly enough, this was quite hard to find an example of.

HTML5 and IPs

Traditionally, when a webpage wants your location, we use the native HTML5. While this isn’t a terrible idea and can have much more accurate results, there is another method to find your users location that doesn’t require the use of HTML5 geolocation, the users IP address.

HTML5 Geolocation

The most accurate approach to locating your users is to use HTML 5’s built in geolocation feature. Due to the accuracy, this is the approach I opted to use for Geotinerary.

Here is a code snippet for HTML 5 Geolocation:

Geolocating IP Addresses

If you are concerned with There are a swath of many great GeoIP providers, but for this project I decided upon Free GeoIP for its open data and ease of use. While the location is not as great, it’s all about what you need from your data.

Here is a code snippet for Geolocating IP Addresses:

Deciding upon which method to use depends on use case. Since I had a need for specific locations, I went with the traditional HTML 5 geolocation. If I were to aggregate data at a national (or global) scale, then GeoIP is a fantastic use.