2
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
};
当我使用注释掉线,该程序工作正常,它缩放到硬编码位置。当我使用pos.coords行时,没有任何反应。我说错了吗?我不能像这样把它放在我的变量中,还是会返回其他东西?