Google Maps API标记无法显示

时间:2014-01-30 09:25:49

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

我刚开始使用Goggle Maps API并且我已经按照所有说明进行操作但由于某种原因地图显示,但显示特定位置的标记没有显示。

以下是我正在使用的代码:

function initialize() {
    var map_canvas = document.getElementById('map_canvas');
    var myLatIng = new google.maps.LatLng(-1.288902, 36.806304);

    var map_options = {
      center: myLatIng,
      zoom: 19
    }
  var map = new google.maps.Map(map_canvas, map_options);

  var contentString = '<h2>Capacity Development Institute</h2><p>NAS Apartments, Milimani Road,<br>P.O.Box 33411 - 00600, Nairobi, Kenya</p>';

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

    var marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          title: 'Capacity Development Institute'
      });

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

  google.maps.event.addDomListener(window, 'load', initialize);

我究竟做错了什么?

由于

1 个答案:

答案 0 :(得分:3)

如果您查看控制台日志,您将看到一条消息:

Uncaught ReferenceError: myLatlng is not defined

你有一个错字:

var myLatIng = new google.maps.LatLng(-1.288902, 36.806304);

应该是

var myLatlng= new google.maps.LatLng(-1.288902, 36.806304);

所以你必须在map_options和marker定义中将它更改为相同。

相关问题