This is what I have:
var position;
navigator.geolocation.getCurrentPosition(onSuccess, onError);
function onSuccess(pos) {
position = { latitude: pos.coords.latitude, longitude: pos.coords.longitude} ;
//position = { latitude:43.465099,longitude:-80.520344};
}
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
var myOptions = {
center: new google.maps.LatLng(
position.latitude,position.longitude
),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
When I use the commented out line, the program works fine and it zooms to the hardcoded location. When I use the pos.coords line, nothing happens. Am I calling it wrong? Am I not able to just put it in my variable like that or does it return something else?
You appear to be using the result properly but I would encode the JSON a bit differently: