【发布时间】:2017-07-18 04:57:46
【问题描述】:
这是我在 javascript 文件下运行时遇到的错误
getCurrentPosition() 和 watchPosition() 不再适用于不安全的来源。要使用此功能,您应该考虑将应用程序切换到安全源,例如 HTTPS。有关详细信息,请参阅 https。
这是我的 javascript 文件
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA4HSRrQSje--aI6ImtJF30s5ezaUWxsow&libraries=places"></script>
<script>
function getLocation()
{
console.log("In geolocation");
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else
{
print("Browser doesn't support geolocation");
}
function showPosition(position)
{
console.log("in show position");
dest_lat=position.coords.latitude;
dest_long=position.coords.longitude;
url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='+ dest_lat + ',' + dest_long + '&sensor=false';
$.get(url, function(data)
{
if (data.status == 'OK')
{
map.setCenter(data.results[0].geometry.location);
console.log("Dragaed lat "+marker.getPosition().lat());
console.log("Dragged lng "+marker.getPosition().lng());
console.log("Address "+data.results[0].formatted_address);
}
});
}
</script>
</head>
<body>
<input type="button" value="LocateMe" onclick="getLocation();"/>
</body>
</html>
【问题讨论】:
-
报错信息很清楚,有什么不明白的地方?您不能在不是通过 https 提供的页面上使用这些功能。
-
嘿!宝。我可以看到错误。我能够理解它。但是我在解决它时遇到了问题。最后,我想通了。只是我是网络编程的新手。谢谢。
-
我相信它应该在
localhost中工作,因为它被视为安全的。至少在谷歌浏览器中。
标签: javascript html google-maps google-maps-api-3