Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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
谷歌地图API Javascript。无法加载信息窗口_Javascript_Google Maps Api 3_Infowindow - Fatal编程技术网

谷歌地图API Javascript。无法加载信息窗口

谷歌地图API Javascript。无法加载信息窗口,javascript,google-maps-api-3,infowindow,Javascript,Google Maps Api 3,Infowindow,我一直在尝试在marker上加载信息窗口,但无法加载。我试图在用户单击标记后加载信息窗口。问题是否是因为我没有在初始化中定义eventListener?我试过了,但还是不行!有人能帮忙吗 javascript代码是: var zwsid = "*My_API_Key*"; var request = new XMLHttpRequest(); var mapObj; var map_Estate; function initialize() { geocoder = new google

我一直在尝试在marker上加载信息窗口,但无法加载。我试图在用户单击标记后加载信息窗口。问题是否是因为我没有在初始化中定义eventListener?我试过了,但还是不行!有人能帮忙吗

javascript代码是:

var zwsid = "*My_API_Key*"; 
var request = new XMLHttpRequest();
var mapObj;
var map_Estate;
function initialize() 
{
  geocoder = new google.maps.Geocoder();
  var defaultLoc = new google.maps.LatLng(51.5286416, -0.1015987); //defines location of the Map
  map_Estate =        // defines the properties of the map
  {  center: defaultLoc,
     zoom:16,
     mapTypeId: google.maps.MapTypeId.ROADMAP  }
  mapObj = new google.maps.Map( document.getElementById('mapArea'), map_Estate);  //creates a object to load in HTML file
}

function xml_to_string ( xml_node ) 
{
  var value1, marker;
    //document.getElementById("test1").innerHTML = "Entered addrMap";
    var address = document.getElementById('address').value;

    geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) 
    {
      document.getElementById("test1").innerHTML = " LATLNG is: "+ results[0].geometry.location+ " STATUS: " + status;
             mapObj.setCenter(results[0].geometry.location);
             marker = new google.maps.Marker({
                                                map: mapObj,
                                                position: results[0].geometry.location  });                 
    }  
    else 
    {   alert('Geocode was not successful for the following reason: ' + status);  }
    });    
       google.maps.event.addListener(marker, 'click', function()
    {
        var infoProp = new google.maps.InfoWindow({ content: "Value of the property is "});
        infoProp.open(mapObj, marker);
} );           

if (xml_node.xml)
value1 = xml_node.xml;
var xml_serializer = new XMLSerializer();
value1 =  xml_serializer.serializeToString(xml_node);  
document.getElementById("text1").innerHTML += "City: "+document.getElementById("city").value +
                                                 ",  State: "+document.getElementById("state").value+ ", Cost: "+value1+"<br></br>";
}

function displayResult () 
{
    if (request.readyState == 4) 
    {
    var xml = request.responseXML.documentElement;
    var value = xml.getElementsByTagName("zestimate")[0].getElementsByTagName("amount")[0];        
    //document.getElementById("output").innerHTML = xml_to_string(value);
    xml_to_string(value);
}
}

function sendRequest () {
request.onreadystatechange = displayResult;
var address = document.getElementById("address").value;
var city = document.getElementById("city").value;
var state = document.getElementById("state").value;
var zipcode = document.getElementById("zipcode").value;
request.open("GET","proxy.php?zws-id="+zwsid+"&address="+address+"&citystatezip="+city+"+"+state+"+"+zipcode);
request.withCredentials = "true";
request.send(null);
}

当您将侦听器移动到if语句中时,它将工作

除此之外,我建议清理并构建代码

IF语句JS

    if (status == google.maps.GeocoderStatus.OK) 
    {
      document.getElementById("test1").innerHTML = " LATLNG is: "+ results[0].geometry.location+ " STATUS: " + status;
             mapObj.setCenter(results[0].geometry.location);
             marker = new google.maps.Marker({
                                                map: mapObj,
                                                position: results[0].geometry.location  });

google.maps.event.addListener(marker, 'click', function()
    {
        var infoProp = new google.maps.InfoWindow({ content: "Value of the property is "});
        infoProp.open(mapObj, marker);
} );         
    } 

在这里使用fiddle:

添加一个简单的jsfiddle,使我们能够更轻松地帮助您。请使用您的html和xml文件更新此fiddle。谢谢@bnz我已经用HTML更新了JSFIDLE文件。基本上,我试图实现的是通过使用Zillow API,我试图提取房地产的价格。因此,xml文件与API连接。请共享更新的API的urlfiddle@bnz你能告诉我这是什么意思吗:函数xml\u到字符串xml\u节点{var value1;ifxml_node.xml value1=xml_node.xml;var xml_serializer=new XMLSerializer;value1=xml_serializetoString xml_node;一些值来自xml文件。不知道这些是标记还是其他api zillow。你能共享其中一个xml文件吗?我没有xml文件。我只有api密钥!