Google maps 地图标记赢得';不显示

Google maps 地图标记赢得';不显示,google-maps,google-maps-api-3,map,Google Maps,Google Maps Api 3,Map,我完全迷路了,我的记号笔不会出现在地图上。我完全按照GoogleMaps示例中所示的方式进行了操作。我无法让标记出现在我的地图上。图标图像与html页面位于同一文件夹中 $("#b1").on("click",function(){ function initialize(){ var myLatLng = new google.maps.LatLng(40.7404, -74.1789); var mapOptions = { zoom:5, cen

我完全迷路了,我的记号笔不会出现在地图上。我完全按照GoogleMaps示例中所示的方式进行了操作。我无法让标记出现在我的地图上。图标图像与html页面位于同一文件夹中

$("#b1").on("click",function(){
  function initialize(){
    var myLatLng = new google.maps.LatLng(40.7404, -74.1789);
    var mapOptions = {
      zoom:5,
      center: myLatLng
    }
    var map=new google.maps.Map(document.getElementById("googleMap"),mapOptions);
    var image = 'marker.png';
    var myLatLng = new google.maps.LatLng(40.64043,-74.2789);
    var Name = new google.maps.Marker({
      position: myLatlng,
      map: map,
      icon: image
    });
    marker.setMap(map);
  });
  google.maps.event.addDomListener(window, 'load', initialise);
更新:

我明白了。我需要有
google.maps.event.addDomListener(窗口“加载”,初始化)在函数外部

更新2:
我不需要在
google.maps.event.addDomListener(窗口'load',initialise')中设置'initialize'如果我这样做。它将只创建一个标记。删除它之后,标记器正在处理我拥有的所有30个onClick列表。是的,我不需要函数initialize()

1:您使用了错误的标记变量来设置映射,将标记初始化为全局变量

2:要获得地图显示,您必须使用
google.maps.event.adddomstener(document.getElementById('yourbuttonid'),'click',initialize)

3:它将不具有初始化功能


当图像和HTML页面位于同一文件夹中时,应删除斜杠(路径开头的斜杠标记根文件夹,因此图像应位于服务器的文档根目录中)。我删除了斜杠,但它仍然没有显示。您使用“var name”作为标记实例,因此将其命名为.setMap(map);警告:初始化≠ 初始化