0

很奇怪。当我在本地计算机上预览我的地图文件时,它工作得很好,并且出现了标记。但是,当我上传到我的网络服务器时,标记消失了。文件完全一样...

有谁知道发生了什么?

http://www.andyinman.com/googlemap/test2.html

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>St. Joseph Larceny Map</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
        type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[

[ { featureType: "landscape.natural", stylers: [ { hue: "#3bff00" }, { visibility: "off" } ] }]

var customIcons = {
  restaurant: {
    icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  },
  bar: {
    icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  }
};

function load() {
  var map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(39.7579, -94.8365),
    zoom: 13,
    mapTypeId: 'roadmap'
  });
  var infoWindow = new google.maps.InfoWindow;

  // Change this depending on the name of your PHP file
  downloadUrl("larceny1.xml", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var name = markers[i].getAttribute("name");
      var address = markers[i].getAttribute("address");
      var type = markers[i].getAttribute("type");
      var point = new google.maps.LatLng(
          parseFloat(markers[i].getAttribute("lat")),
          parseFloat(markers[i].getAttribute("lng")));
      var html = "<b>" + name + "</b> <br/>" + address;
      var icon = customIcons[type] || {};
      var marker = new google.maps.Marker({
        map: map,
        position: point,
        icon: icon.icon,
        shadow: icon.shadow
      });
      bindInfoWindow(marker, map, infoWindow, html);
    }
  });
}

function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
}

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function doNothing() {}

//]]>
  </script>
  </head>

  <body onload="load()">
    <div id="map" style="width: 100%; height: 100%"></div>

4

2 回答 2

1

它适用于 Chrome、Firefox 和 IE8。也许你有一个坏的 xml 副本卡在浏览器缓存中(你使用的是哪个浏览器?)

于 2012-07-05T04:59:09.323 回答
0

尝试使用您自己的合法密钥。这条线

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

应该看起来更像这样

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

您可以在他们的主页上申请自己的 Google Maps API 密钥。由于带宽等情况,不允许普通用户使用默认 Google 密钥进行发布有几个原因。因此,大容量公司必须付费才能获得 Google Maps 密钥的许可证,但供您使用,免费密钥可能会正常工作。

于 2012-07-05T05:32:35.220 回答