2012-12-04 32 views
0

我把geolocation.watchPosition API,但是當我在瀏覽器上運行它時,地圖根本不顯示。任何人都可以請告訴我如何解決這個問題?geolocation.watchposition不工作,請幫我

<script> 

if (navigator.geolocation) 
{ 
    function showPositionOnMap(position) 
    { 
     var point = new google.maps.LatLng(position.coords.latitude, 
     position.coords.longitude), 

     myOptions = { 
      zoom: 15, 
      center: point, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }, 

     mapDiv = document.getElementById("mapDiv"), 
     map = new google.maps.Map(mapDiv, myOptions), 
       marker = new google.maps.Marker({ 
      position: point, 
      map: map, 
      title: "You are here" 
      }); 
    } 

    var timeoutVal = 10 * 1000 * 1000; 
    navigator.geolocation.watchPosition(showPositionOnMap, errorMessage, 
    { 
     enableHighAccuracy: true, timeout: timeoutVal, maximumAge: 0 }); 
} 

else 
{ 
    alert("Geolocation is not supported by this browser"); 
} 

</script> 

回答

0

使用現有的errorMessage函數,此代碼運行良好。也許,您的瀏覽器阻止了地理定位,因爲您沒有允許它。

相關問題