Uncaught Type Error: Can not read property latitude-Collection of common programming errors
This is part of a function I have written
watchlocation: function() {
console.log("watchlocation Started");
if (watchProcess == null) {
watchProcess = navigator.geolocation.watchPosition(locationcheck.handle_geolocation_query_success, locationcheck.handle_errors, {enableHighAccuracy:true});
}
if(position.coords.latitude == null) {
var Lat = '52.5960';
console.log("latitude Set Manually");
}
else {
var Lat = position.coords.latitude;
console.log("latitude Set Automatically");
};
if(position.coords.longitude == null) {
var lon = '-1.9110';
console.log("longitude Set Manually");
}
else {
var lon = position.coords.longitude;
console.log("longitude Set Automatically");
};
locationcheck.handle_geolocation_query_successalt(position.coords.latitude,position.coords.longitude);
console.log("watchlocation Position Passed");
},
Every time I try and access position.coords.latitude or position.coords.longitude console says its
‘Uncaught Type Error: Can not read property ‘latitude’ of undefined’ & ‘Uncaught Type Error: Can not read property ‘longitude’ of undefined
The end result of what I am trying to do here is grab the current location through the HTLM5 standard, if that does not work substitute the lat lon global variables.
I suspect its probably down to my methods here as I am still learning the best way to do things as I have been able to access position.coords.latitude,position.coords.longitude as part of an alert box before now.
TIA
Terran
EDIT Jörn Berkefelds comment that I had var postion = “”; else where was correct – I removed it and it resolved the problem.
T
Originally posted 2013-11-09 20:18:51.