GetcurrentPosition在部署后不起作用 [英] GetcurrentPosition doesn't work once deployed
问题描述
我试图初始化一个以当前用户位置为中心的地图并标记。在本地一切都很好,但是当我将html页面部署到Google Appengine时,它只显示没有地理定位的地图...我错了哪里?
Thanks!
I'm trying to initialize a Map centered and with a marker on current user's position. In local everything fine, but when i deploy the html page to Google Appengine, it shows just the map without the geolocalization... Where I'm wrong? Thanks!
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);
});
}
推荐答案
< Chrome浏览器不再支持不安全来源的地理位置。您必须使用HTTPS://如果您要使用地理定位。
Chrome no longer supports geolocation on insecure origins. You must use HTTPS:// if you want to use geolocation.
请参阅控制台中的消息:
See the message in the console:
getCurrentPosition()和watchPosition()在不安全的来源上被弃用。要使用此功能,您应该考虑将应用程序切换到安全的来源,例如HTTPS。请参阅 https: //sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins 了解更多详情。
这篇关于GetcurrentPosition在部署后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!