Created
March 24, 2019 18:33
-
-
Save isauravmanitripathi/1a5501c1b8b92c379ae195f2da887cfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<script> | |
$(document).ready(function () { | |
//wire up button click | |
$('#go').click(function () { | |
// test for presence of geolocation | |
if (navigator && navigator.geolocation) { | |
// make the request for the user's position | |
navigator.geolocation.getCurrentPosition(geo_sucess, geo_error); | |
} else { | |
// use MaxMind IP to location API fallback | |
printLatLong(geoip_latitude(), geoip_longitude(), true); | |
} | |
}); | |
}); | |
// output lat and long | |
function printLatLong(latitude, longitude, isMaxMind) { | |
$('body').append('<p>Lat: ' + lat + '</p>'); | |
$('body').append('<p>Long: ' + long + '</p>'); | |
// if we use MaxMind for location, add attribution link | |
if (isMaxMind) { | |
$('body').append('<p> <a href = "http://www.maxmind.com" target = "_blank"> IP to Location Service Provided by MaxMind</p>') | |
} | |
} | |
function geo_error(err){ | |
// instead of displaying an error, fall back to MaxMind IP to location library printLatLong(geoip_latitude(), geoip_longitude(), true); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment