hope all is well.
I am using Version 7.0.
This morning I was struggling with something I thought should be rather simple. Providing alternative search results in a Store Locator scenario. (Just like here – http://www.bing.com/maps)
I make a geocode request to Bing Maps Rest service like so:
var geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations?query=" + encodeURI(searchString) + "&output=json&jsonp=GeocodeCallbackSearch&key=" + credentials;
This all works great! I can capture my result returned into my function and parse it just fine as long as the user has typed in a query which had a matching geocode.
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)
}
Error: I keep getting result.resourceSets[i].resources[i].name is undefined.
I know they are buried in there some where because the length is sometimes greater than 1!
Am I mus-understanding that result.resourceSets[0].resources.length is the count of geocode results returned?
Thanks in advanced!
Easy fix, the bolded needed to be changed, ofcourse!