【发布时间】:2016-09-08 15:17:06
【问题描述】:
我正在尝试初始化一个以当前用户位置为中心并带有标记的地图。在本地一切都很好,但是当我将 html 页面部署到 Google Appengine 时,它只显示没有地理定位的地图......我错在哪里? 谢谢!
var marker;
function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 44.415, lng: 10.374},
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
marker = new google.maps.Marker({
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: {lat: position.coords.latitude, lng: position.coords.longitude}
});
marker.addListener('click', toggleBounce);
});
}
【问题讨论】:
-
是否通过 HTTPS 部署:?你在什么浏览器上测试?
-
1-dot-glance-1294.appspot.com/mappa.html 在 chrome 上测试
-
在控制台中查看,除了javascript错误,还会看到:
getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. Seesites.google.com/a/chromium.org/dev/Home/chromium-security/…for more details.
标签: javascript html google-maps google-app-engine