我使用的是7.0版。
今天早上我正在努力学习一些我认为应该相当简单的事情。在商店定位器方案中提供备用搜索结果。 (就像这里 - http://www.bing.com/maps)
我向Bing Maps Rest服务提出地理编码请求,如下所示:
var geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations?query=" + encodeURI(searchString) + "&output=json&jsonp=GeocodeCallbackSearch&key=" + credentials;
这一切都很棒!只要用户输入了具有匹配地理编码的查询,我就可以捕获返回到我的函数中的结果并解析它。
function GeocodeCallbackSearch(result) {
try
{
alert(result.resourceSets[0].resources.length);
// When the user searches an address that isn't quite right, I notice that the
// Length of the result set is greater then 1.
// I would like to get at these so I can provide the "Did you Know"
// functionality.
// This is where I am having problems accessing the other results
for (var i =0; i < result.resourceSets[0].resources.length;i++)
{
alert (result.resourceSets[i].resources[i].name);
}
}
catch(err){
alert(err.message)
}
错误:我一直收到result.resourceSets [i] .resources [i] .name未定义。
我知道他们被埋在那里,因为长度有时大于1! 我是否理解result.resourceSets [0] .resources.length是返回的地理编码结果的数量?
先谢谢!
答案 0 :(得分:0)
for (var i =0; i < result.resourceSets[0].resources.length;i++)
{
alert (result.**resourceSets[i]**.resources[i].name);
}
易于修复,需要更改粗体,当然!
// This is where I am having problems accessing the other results
for (var i =0; i < result.resourceSets[0].resources.length;i++)
{
alert (result**.resourceSets[0]**.resources[i].name);
}