【发布时间】: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