Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在gmap3中检索到错误的标记_Javascript_Google Maps_Google Maps Api 3_Jquery Gmap3 - Fatal编程技术网

Javascript 在gmap3中检索到错误的标记

Javascript 在gmap3中检索到错误的标记,javascript,google-maps,google-maps-api-3,jquery-gmap3,Javascript,Google Maps,Google Maps Api 3,Jquery Gmap3,在gmap3谷歌地图库中,我试图创建一个函数,用一个信息窗口创建一个标记 函数addMarker(地图、标记、内容){ 地图标记(标记) .信息窗口({ “内容”:内容 }) .then(功能(信息窗口){ var map=this.get(0); var marker=this.get(1);//函数“get”从一开始就检索链接结果,索引永远不会更改 使用“then”将其本地存储在函数中 function addMarker(map, marker, content) { map.m

在gmap3谷歌地图库中,我试图创建一个函数,用一个信息窗口创建一个标记

函数addMarker(地图、标记、内容){
地图标记(标记)
.信息窗口({
“内容”:内容
})
.then(功能(信息窗口){
var map=this.get(0);
var marker=this.get(1);//函数“get”从一开始就检索链接结果,索引永远不会更改

使用“then”将其本地存储在函数中

function addMarker(map, marker, content) {
    map.marker(marker)
    .infowindow({
        'content' : content
    })
    .then(function (infowindow) {
        var map = this.get(0);
        var marker = this.get(1);  // <---- this gets the first marker on both times I call addMarker, i.e. uluru
        marker.addListener('click', function(event, data) {
            infowindow.open(map, this);
        });
    });
}

$(document).ready(function() {

    var uluru = {lat: -25.363, lng: 131.044};

    var map = $('#map')
      .gmap3({
        zoom: 4,
        center: uluru
      });

    addMarker(map, {
        position: uluru
    }, "text");
    addMarker(map, {
        position: {lat: 48.8620722, lng: 2.352047}
    }, "text2");
});
function addMarker(map, marker, content) {
  var gmMarker;
  map
      .marker(marker)
      .then(function (m) {
        gmMarker = m;
      })
      .infowindow({
        'content' : content
      })
      .then(function (infowindow) {
        var map = this.get(0);
        gmMarker.addListener('click', function(event, data) {
          infowindow.open(map, this);
        });
      });
}