4

我是谷歌地图的新手,只是为当前位置加载谷歌地图但navigator.geolocation.getCurrentPosition()抛出错误(

即 getCurrentPosition() 不再处理不安全的连接

)。

我的代码看起来像:

function initialize() {

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function (p) {
            var sMap = null;
            var marker = null;
            sMap = new GMaps({
                div: '#regestration-map',
                zoom: 13,
                lat: p.coords.latitude,
                lng: p.coords.longitude ,
                //center: center,
                scrollwheel: false ,
                styles: [ {stylers: [ { "saturation":-100 }, { "lightness": 0 }, { "gamma": 1 } ]}]
             }); 
           marker = sMap.addMarker({
                lat: p.coords.latitude,
                lng: p.coords.longitude ,
                map :sMap,      
                icon : map_marker,
                title: "<div style = 'height:60px;width:200px'><b>Your location:</b><br />Latitude: " + p.coords.latitude + "<br />Longitude: " + p.coords.longitude
            }); 

            sMap.addListener('click',function(e){
                marker.setPosition(e.latLng);
                marker.title = "<div style = 'height:60px;width:200px'><b>Your location:</b><br />Latitude: " + e.latLng.lat() + "<br />Longitude: " + e.latLng.lng()
            });

            marker.addListener('click',function(e){
                var infoWindow = new google.maps.InfoWindow();
                infoWindow.setContent(marker.title);
                infoWindow.open(sMap, marker);
            });
        });
    }else {
        alert('Geo Location feature is not supported in this browser.');
    }
}

我在 UAT 环境中上传代码,连接不是安全的演示目的,没有任何 SSL 层。

是否有任何解决方案可以通过 HTTP 连接获取当前的纬度和经度?

4

1 回答 1

2

来自谷歌文档 https://developers.google.com/maps/documentation/javascript/tutorial

HTTPS 或 HTTP

我们认为网络安全非常重要,建议尽可能使用 HTTPS。作为我们努力提高网络安全性的一部分,我们已通过 HTTPS 提供所有 Maps JavaScript API。使用 HTTPS 加密可以让您的网站更安全,更能抵御窥探或篡改。

我们建议使用上面提供的标记通过 HTTPS 加载 Maps JavaScript API。

如果需要,您可以通过请求http://maps.googleapis.com/http://maps.google.cn(中国用户)通过 HTTP 加载 Maps JavaScript API。

于 2018-05-03T07:13:28.270 回答