財產「COORDS」我與地理位置的谷歌地圖API搞亂。一切工作正常,但我不斷收到這個錯誤在我的控制檯:地理位置遺漏的類型錯誤:無法讀取的不確定
Uncaught TypeError: Cannot read property 'coords' of undefined
這裏是我的緣檢查:
// Does this browser support geolocation?
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(initialize, locationError);
} else {
showError("Your browser does not support Geolocation!");
}
我的成功處理程序:
function initialize(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var acc = position.coords.accuracy;
// Debugging
console.log(position.coords);
console.log("Accuracy: "+acc+"\nLatitude: "+lat+"\nLongitude: "+lon);
// Google Maps API
var myLatlng = new google.maps.LatLng(lat,lon);
var mapOptions = {
center: new google.maps.LatLng(lat, lon),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
}
我然後初始化地圖在我身上的標籤<body id="map" onload="initialize()">
地圖呈現良好,所有內容都按預期工作。當我登錄position.coords
到我的控制檯時,我得到一個乾淨的讀數。爲什麼我一直收到這個錯誤?渲染沒有結果
谷歌和SO搜索...
乾杯
太好了,謝謝你們! – robabby