0

我有 Google Maps v3 的项目。而且我在多个标记的信息窗口中显示数据时遇到问题。当我尝试为每个标记制作信息窗口时,地图根本不显示。我确定我错过了一些东西,但我不知道该怎么做。所以这是我的代码:

...
<script type="text/javascript">
        var pinImage = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_xpin_letter_withshadow&chld=pin_star|%E2%80%A2|CC3300|000000|FF9900",
        new google.maps.Size (70, 83),
        new google.maps.Point (0,0),
        new google.maps.Point (10,34));
    var pinShadow = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
        new google.maps.Size (89, 85),
        new google.maps.Point (0, 0),
        new google.maps.point (12, 35));
        var map;
    function initialize() {
    var myLatlng = new google.maps.LatLng(41.258531,-96.012599);
    var myOptions = {
    zoom: 2,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var infoWindow = new google.maps.InfoWindow;
    <?php
    $posisi = array();
    $keterangan = array();
    foreach ($integer as $lokasi) {
    $query = "SELECT cl.locId, cl.country as country, cl.region as region, cl.city as city, cl.postalCode as postalCode, cl.latitude as latitude, cl.longitude as longitude, cl.metroCode as metroCode, cl.areaCode as areaCode
    FROM (SELECT locId as idcihuy FROM cityblocks WHERE $lokasi BETWEEN startIpNum AND endIpNum) cb, citylocation cl WHERE cb.idcihuy = cl.locId";
    $result = mysql_query($query);
    while ($location = @mysql_fetch_assoc($result)){
    $posisi[]= 'new google.maps.LatLng(' . $location['latitude'] . ', ' . $location['longitude'] . ')';
    $keterangan[]= '(' . $location['country'] . ', ' . $location['region'] . ', ' . $location['city'] . ')';
    }
    }
    ?>
     var keterangan = new Array();
 var point = [<?php echo implode(',', $posisi) ?>];
 var lokasi = [<?php echo implode(',', $keterangan) ?>];
 var icon = pinImage;
 for (var i = 0; i < point.length; i++) {
 var html = "<b>" + lokasi[i] + "</b> <br/>" + point[i];
     var marker = new google.maps.Marker({
        map: map,
        position: point[i],
        icon: pinImage,
        shadow: pinShadow
        });
        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);
      });
    }
    </script>

这是 HTML 代码(浏览器输出):

...
var pinImage = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_xpin_letter_withshadow&chld=pin_star|%E2%80%A2|CC3300|000000|FF9900",

        new google.maps.Size (70, 83),

        new google.maps.Point (0,0),

        new google.maps.Point (10,34));

    var pinShadow = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",

        new google.maps.Size (89, 85),

        new google.maps.Point (0, 0),

        new google.maps.point (12, 35));

        var map;

    function initialize() {

    var myLatlng = new google.maps.LatLng(41.258531,-96.012599);

    var myOptions = {

    zoom: 2,

    center: myLatlng,

    mapTypeId: google.maps.MapTypeId.ROADMAP

    }

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

    var infoWindow = new google.maps.InfoWindow;

         var keterangan = new Array();

     var point = [new google.maps.LatLng(20.0000, 77.0000),new google.maps.LatLng(20.0000, 77.0000),new google.maps.LatLng(38.0000, -97.0000),new google.maps.LatLng(51.7500, -1.2500)];

     var lokasi = [(IN, , ),(IN, , ),(US, , ),(GB, K2, Oxford)];

     var icon = pinImage;

     for (var i = 0; i < point.length; i++) {

      var html = "<b>" + lokasi[i] + "</b> <br/>" + point[i];

     var marker = new google.maps.Marker({

        map: map,

        position: point[i],

        icon: pinImage,

        shadow: pinShadow

        });

        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);

      });

    }

    </script>

请帮我解决这个问题。我真的很需要帮助。谢谢你。

4

1 回答 1

1

在这一行大写指向Point:(阴影)new google.maps.Point (12, 35));

现在您在 JavaScript 中缺少引号lokasi,因为它不是正确的数组。所以 html 永远不会被构建。

我相信PHP中的这一行

$keterangan[]= '(' . $location['country'] . ', ' . $location['region'] . ', ' . $location['city'] . ')';

应该更像这样(注意括号旁边添加的“)

$keterangan[]= '"(' . $location['country'] . ', ' . $location['region'] . ', ' . $location['city'] . ')"';

使 Javascript 看起来像这样

var lokasi = ["(IN, , )","(IN, , )","(US, , )","(GB, K2, Oxford)"];
于 2012-06-08T23:51:43.843 回答