问题描述:

var pos=new google.maps.LatLng(60,100);

navigator.geolocation.getCurrentPosition(function(position){

pos = new google.maps.LatLng(position.coords.latitude,

position.coords.longitude);

map.setCenter(pos);

});

document.getElementById('test').innerHTML+="Before"+pyrmont;

pyrmont = pos;

document.getElementById('test').innerHTML+="After"+pyrmont;

So the result i get is that the variable pos value is not obtained from the function. It seems that the function has its own copy of inside the function and not accessible outside. I did google for this problem and tried as suggested in many posts but in vain.

var pos=new google.maps.LatLng(60,100);

navigator.geolocation.getCurrentPosition(function(position,pos){

pos = new google.maps.LatLng(position.coords.latitude,

position.coords.longitude);

map.setCenter(pos);

})(pos);

document.getElementById('test').innerHTML+="Before"+pyrmont;

pyrmont = pos;

document.getElementById('test').innerHTML+="After"+pyrmont;

相关阅读:
Top