gpt4 book ai didi

javascript - 部署后 GetcurrentPosition 不起作用

转载 作者:行者123 更新时间:2023-12-02 14:39:00 24 4
gpt4 key购买 nike

我正在尝试初始化一个以当前用户位置为中心并带有标记的 map 。在本地,一切都很好,但是当我将 html 页面部署到 Google Appengine 时,它​​只显示 map ,没有地理定位......我哪里错了?谢谢!

var marker;
function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 44.415, lng: 10.374},
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
marker = new google.maps.Marker({
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: {lat: position.coords.latitude, lng: position.coords.longitude}
});
marker.addListener('click', toggleBounce);
});


}

最佳答案

Chrome 不再支持不安全来源的地理定位。如果您想使用地理定位,则必须使用 HTTPS://。

查看控制台中的消息:

getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins for more details.`

关于javascript - 部署后 GetcurrentPosition 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37192827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com