2

我需要有人引导/指导我在哪里编码错误,因为我无法弄清楚我的代码哪里出错了。此代码在我的 IE 和 FF 中运行良好,但在 Chrome 或 Safari 中运行良好。右边,当我单击下拉列表选择时,它将显示所选位置的确切地图。但是在我的 Chrome 和 Safari 中,它只显示了初始地图,而不是显示从列表中选择的位置。

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Maps JavaScript API Example</title>

  <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAn5fGcWgolNQy8U9PV2YsP1P3Knn23Jro&sensor=false"></script>
  <script type="text/javascript">
    // Variables Initialize
    var marker;
    var map;
    var image = "flag.png";
    function initialize(lat,lng) {
      var singapore = new google.maps.LatLng(lat,lng);
      var settings = {
        zoom: 11,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: singapore,  
        mapTypeControl: true,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
            position: google.maps.ControlPosition.TOP_RIGHT},
        navigationControl: true,
        navigationControlOptions: {
            style: google.maps.NavigationControlStyle.SMALL},
        panControl: true,    
        panControlOptions: {
            position: google.maps.ControlPosition.RIGHT_TOP},
        zoomControl: true,
        zoomControlOptions: {
            style: google.maps.ZoomControlStyle.DEFAULT,
            position: google.maps.ControlPosition.LEFT_TOP},
        scaleControl: true,    
        scaleControlOptions: {
            position: google.maps.ControlPosition.BOTTOM_RIGHT}
      };
      map = new google.maps.Map(document.getElementById("map_canvas"), settings);
      marker = new google.maps.Marker({
          map: map,
          draggable:false,
          animation: google.maps.Animation.DROP,
          position: singapore,
          title:"Singapore",
          icon: image
      });
    }
  </script>
  </head>
  <body onload="initialize('1.28563','103.80918')" onunload="GUnload()">
    <select>
        <option onclick="initialize('1.28563','103.80918')">--Select Location--</option>
        <option onclick="initialize('1.28527','103.82682')">Blk 18A Jalan Membina</option>
        <option onclick="initialize('1.28277','103.82562')">Blk 26 Jalan Membina</option>        
        <option onclick="initialize('1.31546','103.766363')">Blk 321-326 Clementi Ave 5</option>
    </select>
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
  </body>
4

2 回答 2

1

添加onclick到 an<option>似乎不是一个好主意。我会改为使用onchangeon<select>并使用value属性来存储 lat/lng:

<select onchange="movemap(this)">
    <option value="1.28563,103.80918">Blk 18a Jln Membina</option>
    ...

function movemap(sel)
{
    var opt = sel.options[sel.selectedIndex],
    vals = opt.value.split(',');

    initialize(vals[0], vals[1]);
}
于 2012-06-19T03:26:17.477 回答
0

center: ramkySG在你的代码中删除怎么样?

于 2012-06-19T03:26:07.900 回答