Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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 Google Map Api v3:单击信息窗口中的按钮时触发操作_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript Google Map Api v3:单击信息窗口中的按钮时触发操作

Javascript Google Map Api v3:单击信息窗口中的按钮时触发操作,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我使用“右键单击”操作在地图上添加标记。 每个标记都有其特定的infowindow,每个infowindow中都有一个表单 当我创建多个标记时,我的代码只触发第一个infowindow值,而不是好的值 google.maps.event.addListener(map, 'rightclick', function(event) { var marker = new google.maps.Marker({ map: map, draggable : true, po

我使用“右键单击”操作在地图上添加标记。 每个标记都有其特定的infowindow,每个infowindow中都有一个表单

当我创建多个标记时,我的代码只触发第一个infowindow值,而不是好的值

google.maps.event.addListener(map, 'rightclick', function(event) {
  var marker = new google.maps.Marker({
    map: map,
    draggable : true,
    position: event.latLng,
    animation: google.maps.Animation.DROP,
  });

  var geocoder = new google.maps.Geocoder();

  geocoder.geocode({'latLng': event.latLng}, function(results, status) {
    if(status == google.maps.GeocoderStatus.OK) {
      var html = "<div class='infobox'>";
      html += "<p>";
      html += "<strong>Lieu : </strong>";
      html += results[0]['formatted_address'];
      html += "</p>";

      html += "<p>";
      html += "<strong>Nombre de place (~) : </strong>";
      html += "<input type='text' class='form_input' name='nb_place' id='nb_place' />";
      html += "</p>";

      html += "<p>";
      html += "<strong>Point d'arrimage : </strong>";
      html += "<input type='checkbox' id='point_arrim' name='point_arrim' />";
      html += "</p>";

      html += "<input type='hidden' id='formatted_address' name='formatted_address' value='"+results[0]['formatted_address']+"' />";
      html += "<input type='hidden' id='geoloc_lat' name='geoloc_lat' value='"+event.latLng.nb+"' />";
      html += "<input type='hidden' id='geoloc_long' name='geoloc_long' value='"+event.latLng.ob+"' />";
      html += '<input type="button" onclick="saveData()" class="info_button" value="Ajouter l\'emplacement"/>'
      html += "</div>";


      var infowindow = new google.maps.InfoWindow({
        map: map,
        content : html
      });
      infowindow.open(map, marker);

      google.maps.event.addListener(infowindow, 'domready', function(){
        console.log("test");
        console.log($(this));
      });
    }
  });
});

function saveData() {
  var nb_place = escape(document.getElementById("nb_place").value);
  var point_arrim = escape(document.getElementById("point_arrim").checked);
  var formatted_address = document.getElementById("formatted_address").value;
  var geoloc_lat = document.getElementById("geoloc_lat").value;
  var geoloc_long = document.getElementById("geoloc_long").value;

  if(!nb_place) nb_place = null;

  var url = "phpsqlinfo_addrow.php?nb_place=" + nb_place + "&point_arrim=" + point_arrim +
    "&formatted_address=" + formatted_address + "&geoloc_lat=" + geoloc_lat + "&geoloc_long=" + geoloc_long;
  downloadUrl(url, function(data, responseCode) {
    if (responseCode == 200 && data.length <= 1) {
      infowindow.close();
      document.getElementById("message").innerHTML = "Location added.";
    }
  });
}
google.maps.event.addListener(映射,'rightclick',函数(事件){
var marker=new google.maps.marker({
地图:地图,
真的,
位置:event.latLng,
动画:google.maps.animation.DROP,
});
var geocoder=new google.maps.geocoder();
geocoder.geocode({'latLng':event.latLng},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
var html=“”;
html+=“”;
html+=“代替:”;
html+=结果[0][“格式化的地址”];
html+=“

”; html+=“”; html+=“地名(~):”; html+=“”; html+=“

”; html+=“”; html+=“点d'arrimage:”; html+=“”; html+=“

”; html+=“”; html+=“”; html+=“”; html+='' html+=“”; var infowindow=new google.maps.infowindow({ 地图:地图, 内容:html }); 信息窗口。打开(地图、标记); google.maps.event.addListener(infowindow,'domready',function(){ 控制台日志(“测试”); log($(this)); }); } }); }); 函数saveData(){ var nb_place=escape(document.getElementById(“nb_place”).value); var point\u arrim=escape(document.getElementById(“point\u arrim”)。选中); var formatted_address=document.getElementById(“formatted_address”).value; var geoloc_lat=document.getElementById(“geoloc_lat”).value; var geoloc_long=document.getElementById(“geoloc_long”).value; 如果(!nb_place)nb_place=null; var url=“phpsqlinfo\u addrow.php?nb\u place=“+nb\u place+”&point\u arrim=“+point\u arrim+ “&formatted_address=“+formatted_address+”&geoloc_lat=“+geoloc_lat+”&geoloc_long=“+geoloc_long; 下载url(url、函数(数据、响应代码){ 如果(responseCode==200&&data.length

var marker=[];
var infowindow=[];
在全局范围内。然后重试

google.maps.event.addListener(map, 'rightclick', function(event) {
        marker.push(new google.maps.Marker({position: event.latLng, map: map}));
        var markIndex = marker.length-1;
    .......................
   ..........................
   infowindow[markIndex] = new google.maps.InfoWindow({
          content: html
   });
   infowindow[markIndex].open(map,marker[markIndex]);

  //You can also add the info window again while clicking on marker if you need

  google.maps.event.addListener(marker[markIndex], 'click', function(e) {
            infowindow[markIndex].open(map,marker[markIndex]);
  }); 
});
此外,在创建html变量时,还要向其添加infowindow索引

html += '<input type="button" onclick="saveData('+markIndex+')" class="info_button" value="Ajouter l\'emplacement"/>';
html+='';
现在,我们可以关闭saveData函数中的特定信息窗口

function saveData(index) {
........
 if (responseCode == 200 && data.length <= 1) {
          infowindow[index].close();
          document.getElementById("message").innerHTML = "Location added.";
        }
}
函数保存数据(索引){
........

如果(responseCode==200&&data.length Nouphal,则由于您的提示,信息窗口将按预期关闭。但是现在,如何发送信息窗口中包含的特定信息?