谷歌地图-多个标记从数据库- phpsqlajax - Java



我试图从数据库中获得不同的标记来渲染到前端。std标记都很好,现在是时候添加红色,绿色标记等。我的头在键盘上敲得太久了。(是的,我是新手-对不起)

在JavaScript控制台,我得到一个错误

在- var customIcons = {

这是我的代码-(提前感谢!)

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

var customIcons = {

"Boat Ramp": {
                icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
                shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png',
                iconAnchor: new GPoint(0,0),
                infoWindowAnchor: new GPoint(0,0)
        },
  "Landbased - Saltwater": {
                        icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png',
                shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png',
                iconAnchor: new GPoint(0,0),
                infoWindowAnchor: new GPoint(0,0)
  },

  "Boat - Salt Water": {
    image: 'http://labs.google.com/ridefinder/images/mm_20_orange.png',
                shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png',
                iconAnchor: new GPoint(0,0),
                infoWindowAnchor: new GPoint(0,0)
  }
};
function load() {
  var map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(-41.284882, 173.268570),
    zoom: 5,
    mapTypeId: 'roadmap'
  });
  var infoWindow = new google.maps.InfoWindow;

  downloadUrl("123.php", function(data) {
    var xml = data.responseXML;
    var Sheet1 = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < Sheet1.length; i++) {
      var Type = Sheet1[i].getAttribute("Type");
      var Description = Sheet1[i].getAttribute("Description");
      var Comments = Sheet1[i].getAttribute("Comments");
      var Lat = Sheet1[i].getAttribute("Lat");
      var Lng = Sheet1[i].getAttribute("Lng");
      var point = new google.maps.LatLng(
          parseFloat(Sheet1[i].getAttribute("Lat")),
          parseFloat(Sheet1[i].getAttribute("Lng")));
      var html = "<b>" + Type + "</b> <br/>" + Description + "<br/>" + Comments +"<b><br/>Latitude " + Lat + "<b><br/>Longitude " + Lng;

      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 drop() {   for (var i =0; i < markerArray.length; i++) {     setTimeout(function() {       addMarkerMethod();     }, i * 200);   } }
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() {}
//]]>

问题是,当你引用3.5.9版本的谷歌地图API,你写的代码是针对版本2。在版本3中不再有GPoint类,这就是为什么你会得到错误。

我建议你在v3中使用google.maps.Marker类。有关更多详细信息,请参阅文档。

相关内容

  • 没有找到相关文章

最新更新