【问题标题】:geolocation.watchposition isn't working, please help megeolocation.watchposition 不起作用,请帮助我
【发布时间】:2012-11-22 02:40:18
【问题描述】:

我输入了 geolocation.watchPosition API,但是当我在浏览器上运行它时,地图根本不显示。谁能告诉我如何解决这个问题?

<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>

【问题讨论】:

    标签: api google-maps-api-3 geolocation


    【解决方案1】:

    使用现有的errorMessage 函数,此代码运行良好。也许,您的浏览器阻止了地理定位,因为您没有允许它。

    【讨论】:

      猜你喜欢
      • 2014-09-15
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 2022-11-26
      • 1970-01-01
      • 2016-01-31
      相关资源
      最近更新 更多