<ol id="logger">
<li>logger</li>
</ol>
<div id="map">Mets moi Ă jour fort</div>
JavaScript
var MY = {
// logger function, used to write stuff in this window ==>
log:function(sLog) {
var oLi = document.createElement('LI');
oLi.innerHTML = sLog;
document.getElementById('logger').appendChild( oLi );
}
};
YUI().use('node-base', function(Y) { // load YUI3, just to use their JS loader
// give that method a Position object as per the specs with latitude and longitude
MY.updateMap = function(oPosition) {
MY.log('Latitude : '+oPosition.coords.latitude);
MY.log('Longitude : '+oPosition.coords.longitude);
// displays a google maps tile
var latitude = oPosition.coords.latitude,
longitude = oPosition.coords.longitude,
sUrl = 'http://maps.google.com/maps/api/staticmap?center='+
latitude+','+longitude+
'&sensor=false&size=350x350'+
'&maptype=roadmap&markers='+
latitude+','+longitude+'6&visible='+
(+latitude+0.015)+','+(+longitude+0.015);
document.getElementById('map').innerHTML = '<img src="'+sUrl+'" >';
};
// sub namespace
MY.geolocation = {};
// wrapper method to acces to geolocation
// give him a callback function
MY.geolocation.getCurrentPosition = function( fSuccess ) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(fSuccess);
} else {
Y.Get.script( 'http://j.maxmind.com/app/geoip.js',
// the maxmind script defines 2 methods returning latitude and longitude from the calling IP
{onSuccess:function() {
fSuccess.call(this, {
// reproduce Position object signature
coords:{
latitude:geoip_latitude(),
longitude:geoip_longitude()
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.