Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Adds geolocation support via JavaScript and a service from to add the lat/long - perfect :)
if (!navigator.geolocation) {
navigator.geolocation = (function (window, document) {
function getCurrentPosition(callback) {
var geourl = '' + Math.random(),
iframe = document.createElement('iframe'),
doc, win; = 'none';
doc = iframe.contentDocument || iframe.contentWindow.document;
win = iframe.contentWindow;
// once the script has loaded, it triggers an onload event
// TODO: cross browser test
iframe.onload = function () {
// assign all the captured values across to our geo object
var geo = {
coords: {
// other values are supported, i.e. accuracy, speed, heading, etc
timestamp: (new Date()).getTime()
// then remove the iframe from the body to clear the memory...I hope!
window.document.body.removeChild(iframe);, geo);
// create a document on the fly;
doc.write('<' + 'script src="' + geourl + '"><' + '/script>');
return {
clearWatch: function () {},
getCurrentPosition: getCurrentPosition,
// TODO shouldn't be too difficult :)
watchPosition: function () {}
})(this, document);

This comment has been minimized.

Copy link

commented Jun 17, 2010

Thanks for alerting me to the MaxMind JavaScript service, I've only used their back end stuff.
However, the page does now say this:
"In order to use this Javascript on your website, a link back to the website should be provided, or a Javascript attribution-free license can be purchased for $250/year."


This comment has been minimized.

Copy link
Owner Author

commented Jun 17, 2010

Ha! That's new!

I've been meaning to convert the code to use Google - let me see if I can't fix this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.