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;
所以我得到的结果是没有从函数中获得变量pos值。似乎该函数在函数内部有自己的副本,并且无法在外部访问。我为谷歌解决了这个问题并按照许多帖子的建议进行了尝试但是徒劳无功。
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;