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

时间:2011-07-09 07:46:08

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

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

在JavaScript控制台中我收到错误

未定义的ReferenceError:未定义GPoint“ - 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() {}

//]]>

1 个答案:

答案 0 :(得分:0)

问题在于,当您引用版本3.5.9的google maps API时,您编写的代码与版本2不同。版本3中没有GPoint类,这就是您收到错误的原因。

我建议您在v3中使用google.maps.Marker类。有关详细信息,请参阅the documentation