javascript - 谷歌地图不支持 HTTP

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

<分区>

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

i.e. getCurrentPosition() no longer working on insecure connection

).

我的代码看起来像:

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 连接获取当前的纬度和经度?

最佳答案

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

HTTPS or HTTP

We think security on the web is pretty important, and recommend using HTTPS whenever possible. As part of our efforts to make the web more secure, we've made all of the Maps JavaScript API available over HTTPS. Using HTTPS encryption makes your site more secure, and more resistant to snooping or tampering.

We recommend loading the Maps JavaScript API over HTTPS using the tag provided above.

If required, you can load the Maps JavaScript API over HTTP by requesting http://maps.googleapis.com/, or http://maps.google.cn for users in China.

关于javascript - 谷歌地图不支持 HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50148765/

相关文章:

javascript - 如何使用绘图管理器从谷歌地图中删除绘制的圆或多边形 - ng2-map

javascript - IE 11 调度事件

javascript - 将元素动态移动到视口(viewport)内部

javascript - 使用 AngularJS 的默认过滤器和用户定义过滤器的输入字段

javascript - 谷歌地图多个标记clickevent

Android:模拟位置几秒钟后变回原始位置

javascript - 放大时增加自定义标记的大小?使用 Google map 和 GeoJSON

javascript - 如何对 Google Maps API 进行跨域 AJAX 调用?

html - Chrome Only Bootstrap + Google Maps Bug

javascript - 如何使这个方法异步?