Google地图标记未显示API v3

Ram*_*los 13 javascript google-maps-api-3

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

继承人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);
    }
Run Code Online (Sandbox Code Playgroud)

ale*_*nis 33

我的猜测是你的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);
}
Run Code Online (Sandbox Code Playgroud)