Uncaught ReferenceError: my function is not defined-Collection of common programming errors
I am trying to build a CakePHP application which will allow a user to update their address information, and then store the new lat/lon in the database. I am using Google’s geocoder to retrieve lat/lon information but my function isn’t working. I have almost no experience with Javascript so I am not sure what I have done wrong. My code is kind of an amalgamation of what I have seen around the internet. Please, if someone could advise me, that would be great.
Here is my geocode function:
function getLatLong(address){
var geo = new google.maps.Geocoder;
var address =;
geo.geocode({'address':address},function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
return results[0].geometry.location;
alert('The address is' + address);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
Above my html, here is the script to call it onLoad of the page:
if(window.attachEvent) {
window.attachEvent('onload', getLatLong());
} else {
if(window.onload) {
var curronload = window.onload;
var newonload = function() {
curronload();
getLatLong();
};
window.onload = newonload;
} else {
window.onload = getLatLong();
}
}
I have in the head of my document:
When I load the page and inspect it with chrome, I see
Uncaught ReferenceError: getLatLong is not defined (anonymous function)1:89
1:106 Uncaught SyntaxError: Unexpected identifier