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