GetcurrentPosition不'一旦部署就无法工作

GetcurrentPosition doesn't work once deployed

本文关键字:部署 工作 GetcurrentPosition      更新时间:2023-09-26

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

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()和watchPosition()在不安全的起源上被弃用。要使用此功能,您应该考虑将应用程序切换到安全的来源,例如HTTPS。看见https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins了解更多详细信息