这个函数是小弟用来解析地址的,
function ShowParkingPoints() {
var adNum=document.getElementById("tableOne").rows.length;
var i;
var j;
var l;
for (i=1;i<adNum;i++)
{
for(j=1;j<5;j++)
{
var k=i-1;
addArray[k]+=document.getElementById("tableOne").rows[i].cells[j].innerText;
}
}
for (i=0;i<adNum-1;i++) //在地图上显示所有的er
{
var image = new google.maps.MarkerImage('images/flag.png',
new google.maps.Size(60, 60),
new google.maps.Point(0,0),
new google.maps.Point(0, 60));
var shape = {
coord: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
geocoder.geocode( { 'address': addArray[i]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var str=results[0].formatted_address;
infowindow.setContent(str);
var er = new google.maps.Marker({
map: map,
icon: image,
shape: shape,
draggable:true,
position: results[0].geometry.location
});
erArray[i]=er;
locationArray[i]=results[0].geometry.location;
alert(addArray[0]);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
map.setCenter(mapCenter);
map.setZoom(13); for(l=0;l<erArray.length;l++) //给每一个er加事件监听
{
google.maps.event.addListener(erArray[l], 'click', function(event) {
makerClicked(event.latLng);
});
//alert(erArray.length);
}
发现在ie8中能用,一到IE9或是chrome中就不能用了。后来通过alert语句发现只要已进入geocoder.geocode( { 'address': addArray[i]}, function(results, status) {
这样一个回调函数,i就立马变成adNum的值,这样的话就没办法将值循环写入数组,下面加事件监听的循环也就失效了。求高人指点啊
function ShowParkingPoints() {
var adNum=document.getElementById("tableOne").rows.length;
var i;
var j;
var l;
for (i=1;i<adNum;i++)
{
for(j=1;j<5;j++)
{
var k=i-1;
addArray[k]+=document.getElementById("tableOne").rows[i].cells[j].innerText;
}
}
for (i=0;i<adNum-1;i++) //在地图上显示所有的er
{
var image = new google.maps.MarkerImage('images/flag.png',
new google.maps.Size(60, 60),
new google.maps.Point(0,0),
new google.maps.Point(0, 60));
var shape = {
coord: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
geocoder.geocode( { 'address': addArray[i]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var str=results[0].formatted_address;
infowindow.setContent(str);
var er = new google.maps.Marker({
map: map,
icon: image,
shape: shape,
draggable:true,
position: results[0].geometry.location
});
erArray[i]=er;
locationArray[i]=results[0].geometry.location;
alert(addArray[0]);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
map.setCenter(mapCenter);
map.setZoom(13); for(l=0;l<erArray.length;l++) //给每一个er加事件监听
{
google.maps.event.addListener(erArray[l], 'click', function(event) {
makerClicked(event.latLng);
});
//alert(erArray.length);
}
发现在ie8中能用,一到IE9或是chrome中就不能用了。后来通过alert语句发现只要已进入geocoder.geocode( { 'address': addArray[i]}, function(results, status) {
这样一个回调函数,i就立马变成adNum的值,这样的话就没办法将值循环写入数组,下面加事件监听的循环也就失效了。求高人指点啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货