我在这里遇到问题。
我想实现地图的第一个默认位置。当用户搜索某个位置时,它应该移动到该位置。简单吧。但我有点失落。
//i define parameter.
var geocodingParams = { searchText: 'location address' };
// Get an instance of the geocoding service:
var geocoder = platform.getGeocodingService();
// Call the geocode method with the geocoding parameters,
// the callback and an error callback function (called if a
// communication error occurs):
geocoder.geocode(geocodingParams, onResult, onError);
// results when success
function onResult(result) {
var locations = result.response.view[0].result;
alert(JSON.stringify(locations));
}
// on Error
function onError(e) {
alert(e);
}
它只给出错误。感谢您的帮助。
答案 0 :(得分:0)
抛出错误的原因是因为找不到地址'位置地址'。
我认为您应该将地址更改为:'425 W Randolph Chicago',然后再试一次。
如果仍然无效,请尝试将result.response.view[0].result;
更改为result.Response.View[0].Result;
此外,您可以做的是检查您是否收到任何回复:
if(result.Response.View)
{
var locations = result.Response.View[0].Result;
alert(JSON.stringify(locations));
}
else
alert("Blank response");`