php - 如何在 google map api v3 中创建可点击的图标?

标签 php javascript google-maps google-maps-api-3

我查看了 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。标记对象未添加到 map 中。

更改此:

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 map api v3 中创建可点击的图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6421855/

相关文章:

PHP 粘性表单下拉列表和复选框

php - 根据文件夹中已存在的名称创建文件

javascript - 按条件提交函数中的表单

javascript - 在javascript中自然排序包含数字,字母和日期和时间的字符串

javascript - 对多个数组中的公共(public)值进行分组

google-maps - kml 阻止高程服务

javascript - Google Geocoder - 将坐标添加到字段

php - 加速ajax/javascript,目前检索数据时滞后太多。一定有更好的方法

java - native map 未显示在代号为 1 的 Android 设备的分层布局中

javascript - 在动态加载的元素上执行函数