![](/img/trans.png)
[英]iPhone Google Maps API V3 User Current location and show Restaurants
[英]Google maps api v3, defining user current location
function onPositionUpdate(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var markerPoint = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: markerPoint,
map: map,
title: 'Your Location'
});
}
function button_clicked() {
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(onPositionUpdate);
else
alert("navigator.geolocation is not available");
}
此代碼正確運行並顯示用戶位置。 當我在家里嘗試這個顯示正確的地址但是當我在另一個地方嘗試這個時,這個代碼沒有顯示正確的地址。 為什么? 我不知道這段代碼是如何運行的(這段代碼是為IP還是其他信息定義的)
你有沒有嘗試過 :
navigator.geolocation.getCurrentPosition(onPositionUpdate() );
不確定你的回調是否必須有括號。 這是我會嘗試的東西。
我還注意到,地理定位需要一點時間才能將近似值縮小到更小的半徑。 可能需要調用位置更新 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.