【问题标题】:GetcurrentPosition doesn't work once deployedGetcurrentPosition 部署后不起作用
【发布时间】:2016-09-08 15:17:06
【问题描述】:

我正在尝试初始化一个以当前用户位置为中心并带有标记的地图。在本地一切都很好,但是当我将 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);
        });


        }

【问题讨论】:

标签: javascript html google-maps google-app-engine


【解决方案1】:

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

在控制台中查看消息:

getCurrentPosition() 和 watchPosition() 在不安全的来源上被弃用。要使用此功能,您应该考虑将应用程序切换到安全源,例如 HTTPS。有关详细信息,请参阅https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins。`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2017-04-09
    • 2018-12-20
    • 2021-04-30
    • 2014-07-13
    • 1970-01-01
    相关资源
    最近更新 更多