谷歌地图当前位置绘图

Google maps current location plotting

本文关键字:绘图 位置 谷歌地图      更新时间:2023-09-26

我有下面的代码来查找用户当前位置。

if (navigator.geolocation) {
        // Get current position
        navigator.geolocation.getCurrentPosition(function (position) {
          myLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
          alert(myLatLng);
        },
        function () {
          alert('fallback');
        });
     }

上面的代码工作正常,但它提示用户问'你想与www.something.com分享你的位置吗?'。现在,如果用户不想分享他的位置,那么我需要显示一些警告。我该怎么做呢?

您可以在这里看到您的代码运行良好。

<a href="https://jsfiddle.net/4cbuhhj2/">This jsfiddle</a>