谷歌地图API Javascript.无法加载InfoWindow
Google Maps API Javascript. Cannot load the InfoWindow
我一直试图在标记上加载InfoWindow,但无法加载。我试图在用户单击标记后加载InfoWindow。问题是因为我没有在initialize()中定义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);
} );
}
在这里工作小提琴:http://jsfiddle.net/iambnz/z1dx45rL/
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Emberjs应用程序加载在除Index之外的所有路由上
- 在chrome.tabs.onCreated之后加载HTML页面
- 单击F5时如何停止页面加载
- HTML5音频加载和播放获胜'我不能在iPad上工作
- 跟踪在页面加载时应用内联样式的JavaScript
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- jQuery Lazy加载动画滚动
- Html页面上的多个Base64图像和平滑加载
- 如何创建带有插槽的vue js组件预加载程序
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- 如何使该数据在所有元素中加载
- Chrome扩展没有't在重新加载之前考虑期权价值
- 使用javascript在Flash中加载外部图像
- Ajax文件加载和<输入>文件加载
- 谷歌地图API Javascript.无法加载InfoWindow
- Google InfoWindow没有在循环内部加载