我主要使用PHP代碼,我沒有豐富的JavaScript範圍知識;希望有人能很快解決我的問題。如評論所示,檢查mapCenter.Latitude和mapCenter.Longitude - 它們顯示爲空。firefox位置感知+ javascript範圍
如果將執行,如果位置感知在瀏覽器中可用 - 我敢肯定它適用於我,我用alert()測試它。此外,我知道它正確地抓住position.coords.latitude/longitude,因爲我用alert()的方法測試了這些...但是這些值在函數之外並不是持久的。這可能是微不足道的 - 解決方法是什麼?
function load(){
map = new VEMap('MapDiv');
map.LoadMap();
mapCenter = new VELatLong();
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
mapCenter.Latitude = position.coords.latitude;
mapCenter.Longitude = position.coords.longitude;
});
}
//Inspecting mapCenter.Latitude & mapCenter.Longitude shows empty...
map.SetCenterAndZoom(mapCenter, 15);
...
...
}
謝謝!
這是完美的,謝謝你的代碼,和優秀的解釋。乾杯! – 2011-05-25 22:14:22