【问题标题】:Google Map Not working with HTTP [duplicate]谷歌地图不适用于 HTTP [重复]
【发布时间】:2018-05-03 07:00:26
【问题描述】:

我是谷歌地图的新手,只是为当前位置加载谷歌地图,但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 连接获取当前的纬度和经度?

【问题讨论】:

  • 我相信它现在可以在localhost 中工作,因为它被视为安全。

标签: javascript google-maps google-maps-api-3


【解决方案1】:

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

HTTPS 或 HTTP

我们认为网络安全非常重要,而且 建议尽可能使用 HTTPS。作为我们努力的一部分 让网络更安全,我们制作了所有 Maps JavaScript API 可通过 HTTPS 访问。使用 HTTPS 加密让您的网站更 安全,更能防止窥探或篡改。

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

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

【讨论】:

  • 我只是在寻找能够以某种方式为我提供当前 latLng 的解决方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 2017-01-02
  • 1970-01-01
  • 2020-05-25
  • 2018-01-02
  • 2015-02-23
相关资源
最近更新 更多