13

标记没有出现,我阅读了文档但我找不到问题,有人可以帮我吗?

继承人的js:

function initialize() {
      var mapOptions = {
        center: new google.maps.LatLng(-8.064903, -34.896872),
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

      var marker = new google.maps.Marker({
          position: location,
          title:"Hello World!",
          visible: true
      });
      marker.setMap(map);
    }
4

1 回答 1

37

我的猜测是你的location对象没有定义。尝试将标记位置设置为与地图中心相同的 LatLng 并查看它是否有效:

function initialize() {
  latLng = new google.maps.LatLng(-8.064903, -34.896872)
  var mapOptions = {
    center: latLng,
    zoom: 16,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

  var marker = new google.maps.Marker({
      position: latLng,
      title:"Hello World!",
      visible: true
  });
  marker.setMap(map);
}
于 2013-02-22T14:33:01.537 回答