miran's mess

by Iain Munro

HTML

<div id="message">Loading...</div>

JavaScript

function successHandler(location) {
   var message = document.getElementById("message"),
     html = [];
   html.push("<img width='400' height='400' src='http://maps.google.com/maps/api/staticmap?center=", location.coords.latitude, ",", location.coords.longitude, "&markers=size:small|color:blue|", location.coords.latitude, ",", location.coords.longitude, "&zoom=14&size=256x256&sensor=false' />");
   html.push("<p>Longitude: ", location.coords.longitude, "</p>");
   html.push("<p>Latitude: ", location.coords.latitude, "</p>");
   html.push("<p>Accuracy: ", location.coords.accuracy, " meters</p>");
   message.innerHTML = html.join("");

   //Uncomment it for it to redirect.
   //window.location.href = "myphpfile.php?longitude=" + location.coords.longitude + "&" + "latitude=" + location.coords.latitude + "&" + "accuracy=" +  location.coords.accuracy;
 }

 function errorHandler(error) {
   alert('Attempt to get location failed: ' + error.message);
 }
 if (navigator.geolocation) {
   navigator.geolocation.getCurrentPosition(successHandler, errorHandler);
 } else {
   alert("Please download a modern browser.");
 }