What is the best jQuery plugin that handles HTML5 location?

I want to get lat / long for the browser.

I know that HTML5 has this feature, but I need a complete plugin that gracefully handles older browsers.

Is there a reliable plugin for this?

0
source share
1 answer

Do you really need a plugin for something so simple?

if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); }else{ errorFunction(); } function successFunction(position) { //uses HTML5 if available var lat = position.coords.latitude; var lng = position.coords.longitude; } function errorFunction(){ //uses IP if no HTML5 $.getJSON("http://freegeoip.net/json/", function(res){ var lat = res.latitude; var lng = res.longitude; }); } 

Fiddle

This checks if the HTML5 geolocation API is supported, if any, it gets the coordinates, if it isn't, or if the HTML5 API fails for some reason, it uses the free geoIP service to get the coordinates.

+2
source

All Articles