Google地图地理定位服务无法在Chrome上运行

时间:2017-02-22 07:49:07

标签: javascript geolocation maps

我一直在使用带有谷歌API密钥的地理定位服务。我从这个fiddle获得了代码。

var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 6
});
var infoWindow = new google.maps.InfoWindow({map: map});

// Try HTML5 geolocation.
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
        var pos = {
            lat: position.coords.latitude,
            lng: position.coords.longitude
        };

        infoWindow.setPosition(pos);
        infoWindow.setContent('Location found.');
        map.setCenter(pos);
    }, function() {
        handleLocationError(true, infoWindow, map.getCenter());
    });
} else {
    // Browser doesn't support Geolocation
    handleLocationError(false, infoWindow, map.getCenter());
}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
    infoWindow.setPosition(pos);
    infoWindow.setContent(browserHasGeolocation ?
                      'Error: The Geolocation service failed.' :
                      'Error: Your browser doesn\'t support geolocation.');
}

它曾经完美地工作,直到2天前它在Chrome中突然停止工作并在Firefox中完美运行。

我知道自从Chrome 50发布以来,我必须从安全的位置使用地理位置服务,这不是问题,因为即使是小提琴也是通过HTTPS运行。

我希望有人可以指出我的方向。

0 个答案:

没有答案