0

I have been following a tutorial to set up a google map for my website here and I have completed this, however I now want a custom info box that pops up when you click the icon. (at the moment it pops up with googles default)

I was trying to use this code to do it, but every time I try none of the icons appear.

  <script type="text/javascript">
//<![CDATA[

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'
  }
};

  var labelText = "City Hall";

    var myOptions = {
             content: labelText
            ,boxStyle: {
               border: "1px solid black"
              ,textAlign: "center"
              ,fontSize: "8pt"
              ,width: "50px"
             }
            ,disableAutoPan: true
            ,pixelOffset: new google.maps.Size(-25, 0)
            ,position: new google.maps.LatLng(49.47216, -123.76307)
            ,closeBoxURL: ""
            ,isHidden: false
            ,pane: "mapPane"
            ,enableEventPropagation: true
    };

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

This is the part that im changing at the moment

  var infoWindow = new google.maps.InfoWindow;

to this

  var infoWindow = new infoBox(myOptions);

.

  // Change this depending on the name of your PHP file
  downloadUrl("phpsqlajax_genxml.php", 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>

Any help to say where i'm going wrong would be appreciated

4

1 回答 1

0

假设您已经包含了 infobox-library 并且 php-file 返回了预期的 XML,除了以下内容没有任何问题:

var infoWindow = new infoBox(myOptions);

它一定要是:

var infoWindow = new InfoBox(myOptions);
//-------------------^
于 2013-02-02T21:03:54.590 回答