1

是地理定位谷歌。示例取自这里https://developers.google.com/maps/documentation/javascript/examples/map-geolocation?hl=ru。复制 JAVASCRIPT + HTML 并放置在 localhost 上的虚拟主机http://test.ru上。创建浏览器密钥并添加它。地图已加载,但未在谷歌浏览器中运行地理定位。告诉我问题是什么。这是代码:

 // Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 6
  });
  var infoWindow = new google.maps.InfoWindow({map: map});
  // Try HTML5 geolocation.
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
  var pos = {
    lat: position.coords.latitude,
    lng: position.coords.longitude
  };
  infoWindow.setPosition(pos);
  infoWindow.setContent('Location found.');
  map.setCenter(pos);
}, function() {
  handleLocationError(true, infoWindow, map.getCenter());
});
  } else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
 }
 }
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
  infoWindow.setPosition(pos);
  infoWindow.setContent(browserHasGeolocation ?
                    'Error: The Geolocation service failed.' :
                    'Error: Your browser doesn\'t support geolocation.');
}`
4

1 回答 1

0

问题是自 chrome 50 以来,安全更新消除了没有 http协议的地理定位的可能性。因为你正在尝试这个 url http://test.ru它不会工作。 谷歌详情

希望能帮助到你。问候。

于 2016-06-20T21:13:53.153 回答