谷歌地图标记没有显示API v3

Google maps marker not showing up API v3

本文关键字:显示 API v3 地图 图标 谷歌      更新时间:2023-09-26

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

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

我的猜测是您的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);
}