我查看了api文档,但找不到很多。我被困在尝试使用下面的代码创建一个可点击的图标,该代码显示一个弹出信息框:

  function initialize() {
  var myLatLng = new google.maps.LatLng(52.288, 0.78);
  var myOptions = {
    zoom: 8,
    center: myLatLng,
    mapTypeId: google.maps.MapTypeId.HYBRID
  };

  var map = new google.maps.Map(document.getElementById("map_canvas"),
      myOptions);

<?php

    $sql_launch = mysql_query("SELECT * FROM pred_route WHERE time = (SELECT MIN(time) FROM pred_route)");
    $sql_land = mysql_query("SELECT * FROM pred_route WHERE time = (SELECT MAX(time) FROM pred_route)");
    $sql_pop = mysql_query("SELECT * FROM pred_route WHERE alt = (SELECT MAX(alt) FROM pred_route)");

 ?>

  var contentString = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
    '<div id="bodyContent">'+
    '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
    'sandstone rock formation in the southern part of the '+
    'Northern Territory, central Australia. It lies 335 km (208 mi) '+
    'south west of the nearest large town, Alice Springs; 450 km '+
    '(280 mi) by road. Kata Tjuta and Uluru are the two major '+
    'features of the Uluru - Kata Tjuta National Park. Uluru is '+
    'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
    'Aboriginal people of the area. It has many springs, waterholes, '+
    'rock caves and ancient paintings. Uluru is listed as a World '+
    'Heritage Site.</p>'+
    '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
    'http://en.wikipedia.org/w/index.php?title=Uluru</a> (last visited June 22, 2009).</p>'+
    '</div>'+
    '</div>';

  var infowindow = new google.maps.InfoWindow({
    content: contentString
    });

  var image_balloon = new google.maps.MarkerImage("http://projectstratos.com/images/map/balloon.png",new google.maps.Size(32,37));
  var balloon_longlat = new google.maps.LatLng(<?php echo $current['lat'] . ", " . $current['long']; ?>);
  var balloon = new google.maps.Marker({
      position: balloon_longlat,
      map: map,
      icon: image_balloon
  });

  google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,image_balloon);
  });

最佳答案

您在addListener中引用了错误的对象-使用marker,而您应该使用balloon。 Marker对象未添加到地图。

更改此:

google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,image_balloon);
});




google.maps.event.addListener(balloon, 'click', function() {
    infowindow.open(map,image_balloon);
});

关于php - 如何在Google Maps API v3中创建可点击图标?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6421855/

10-12 01:52