当我上传到我的网络服务器时,谷歌地图v3上的标记消失了

时间:2012-07-05 04:30:30

标签: google-maps google-maps-api-3

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

有谁知道发生了什么事?

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>

2 个答案:

答案 0 :(得分:1)

它适用于Chrome,Firefox和IE8。也许你的浏览器缓存中有一个糟糕的xml副本(你正在使用哪个浏览器?)

答案 1 :(得分: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地图密钥的许可,但是为了您的使用,免费密钥可能会正常工作。