function loadMaps() { google.load("maps", "2", {"callback" : mapsLoaded}); } function initLoader() { var script = document.createElement("script"); script.src = "http://www.google.com/jsapi?key=ABQIAAAAw7Iwp8QdPifsC1Wxvp2jjRT0bhTk_ECr8SMCJ57wLjqypZcrqRQvtD8K-PE2fUZXx0Zv5jZTskV8Hg&callback=loadMaps"; script.type = "text/javascript"; document.getElementsByTagName("head")[0].appendChild(script); } function mapsLoaded(){ if (GBrowserIsCompatible()) { var address= document.getElementById("postcode").value; // Create new geocoding object var geocoder = new GClientGeocoder(); // Retrieve location information from geocode, pass it to getCoordinates() geocoder.getLocations(address, getCoordinates); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } } // This function retrieves the co ordinates function getCoordinates(response){ if(!response.Placemark){ alert("Invalid Postcode"); } else{ // Retrieve the object var place = response.Placemark[0]; // Retrieve the latitude and longitude document.getElementById('lat').value = place.Point.coordinates[1]; document.getElementById('lng').value = place.Point.coordinates[0]; //document.getElementById('postcode').value = place.address; document.getElementById('register_form').submit(); } }