我正在使用Google的API进行多元化检查。我使用以下代码:
var cc='';
function GetMultiCity(g)
{
getHF("divChoice","div").innerHTML='';
var location=getHF("txtCity","input").value;
var b=new GClientGeocoder();
if(location!='')
{
cc=getCountryCode(g);
b.reset();
b.getLocations(location,addAddressToMap);
}
}
function addAddressToMap(response)
{
if(!response||response.Status.code!=200)
{
}
else
{
gResponse=response;
if(response.Placemark.length>1)
{
var oChoiceDiv=getHF("divChoice","div");
oChoiceDiv.innerHTML='';
var html='<ul>';
var ctrmc=0;
for(var n=0;n<response.Placemark.length;n++)
{
if(gResponse.Placemark[n].AddressDetails.Country.CountryNameCode==cc)
{
ctrmc++;
html+=createChoiceLink(n);
}
}
html +='</ul>';
if(ctrmc>1)
{
oChoiceDiv.innerHTML=html;
}
}
else
{
}
}
}
function getCountryCode(g)
{
var a=null;
var i=new Array();
if(g.indexOf(",")>=0)
{
i=g.split(",");
a=i[0];
}
else
{
a=g;
}
return a;
}
function createChoiceLink(ix)
{
var pMark = gResponse.Placemark[ix];
var html = "<li class='choice'><a href='javascript:void(0);' onclick=setCitySource(" + ix + ") >"+pMark.address+"</a></li>";
return html;
}
function setCitySource(ix)
{
citySource=gResponse.Placemark[ix].Point.coordinates[1]+","+gResponse.Placemark[ix].Point.coordinates[0];
independentSource=citySource;
getHF("divChoice","div").innerHTML='';
eval(getHF("hdnJS","input").value);
}
function clickMultiCity(g)
{
GetMultiCity(g);
getHF("divInfo","div").innerHTML=getHF("hdnMultiCity2","input").value+' '+getHF("txtCity","input").value;
setTimeout("document.getElementById('btnSearch').click()",1000);
}
我在荷兰的“Deventer”城市获得response.Placemark.length
的两个结果,那里应该只有一个。