1

我在我的网站上使用以下脚本:

<script type="text/javascript">
    var map;

    function initialize() {
      var mapOptions = {
        zoom: 10,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      map = new google.maps.Map(document.getElementById('map_canvas'),
          mapOptions);
      var kmlLayer = new google.maps.KmlLayer("https://maps.google.ca/maps/ms?ie=UTF8&msa=0&output=kml&msid=210000746142049190989.0004ce14b7a8e95167602");
    kmlLayer.setMap(map);

      // Try HTML5 geolocation
      if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
          var pos = new google.maps.LatLng(position.coords.latitude,
                                           position.coords.longitude);

          var infowindow = new google.maps.InfoWindow({
          map: map,
          position: pos,
          content: 'Location found using HTML5.'
          });
           map.setZoom(14);
          map.setCenter(pos);
        }, function() {
          handleNoGeolocation(true);
        });
      } else {
        // Browser doesn't support Geolocation
        handleNoGeolocation(false);
      }
    }

    function handleNoGeolocation(errorFlag) {
      if (errorFlag) {
        var content = 'Error: The Geolocation service failed.';
      } else {
        var content = 'Error: Your browser doesn\'t support geolocation.';
      }

      var options = {
        map: map,
        position: new google.maps.LatLng(60, 105),
        content: errorFlag
      };

      var infowindow = new google.maps.InfoWindow(options);
      map.setCenter(options.position);
    }

    google.maps.event.addDomListener(window, 'load', initialize);

        </script>

我还使用以下移动设备所需的

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>

但是,当我在移动设备上访问该站点时,我单击查看地图时仍然收到错误“地理定位服务失败”。

对于在移动设备上工作的地理位置,我还缺少其他什么吗?

您可以在该网站的右侧看到该网站和现场示例,如果您向下滚动刚刚超过折叠,您将看到“我在哪里可以得到隆隆声 ” 点击地图。

编辑我认为它与 kmlLayer 似乎在移动设备上默认设置有关?

var kmlLayer = new google.maps.KmlLayer("https://maps.google.ca/maps/ms?ie=UTF8&msa=0&output=kml&msid=210000746142049190989.0004ce14b7a8e95167602");
kmlLayer.setMap(map);
4

1 回答 1

1

根据谷歌地图缩放被覆盖,当使用 kml 文件时

在函数初始化中,将您之前// Try HTML5 geolocation拥有的所有内容替换为:

var mapOptions = { 
    zoom: 8, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
};
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); 
var kmlLayer = new google.maps.KmlLayer("https://maps.google.ca/maps/ms?ie=UTF8&msa=0&output=kml&msid=210000746142049190989.0004ce14b7a8e95167602", { map: map, preserveViewport: true });
于 2013-07-19T19:07:33.267 回答