我正在使用诺基亚 map 进行开发(这是一个很棒的选择,我真的很喜欢它们),但我只能使用 HTML5 获取位置(纬度和经度),但我不知道我所在的位置:/,也许有人可以给出一个想法,如何去做,非常感谢你的帮助。
最佳答案
适用于 JavaScript 3.x 的 map API
当前的 3.x JavaScript API 提供了一个围绕 REST 的精简包装器 Geocoder API .您需要进行ReverseGeocode 搜索,然后从Location 中提取数据。在结果中找到的对象。
可以找到一个完整的反向地理编码示例 here , 但重要的一点(获取地址)如下所示:
function reverseGeocode(platform) {
var geocoder = platform.getGeocodingService(),
reverseGeocodingParameters = {
prox: '52.5309,13.3847,150', // Location
mode: 'retrieveAddresses',
maxresults: '1',
jsonattributes : 1
};
geocoder.reverseGeocode(
reverseGeocodingParameters,
function (result) {
var locations = result.response.view[0].result;
// ... etc.
},
function (error) {
alert('Ooops!');
}
);
}
Maps API for JavaScript 2.x(已弃用)
使用最近弃用 2.x JavaScript API,您需要再次进行ReverseGeocode 搜索,然后从Address 中提取数据。在结果中找到对象。
代码有点长,但重要的一点(获取地址)可以在下面看到:
// Function for receiving search results from places search and process them
var processResults = function (data, requestStatus, requestId) {
var i, len, locations, marker;
if (requestStatus == "OK") {
// The function findPlaces() and reverseGeoCode() of return results in slightly different formats
locations = data.results ? data.results.items : [data.location];
// We check that at least one location has been found
if (locations.length > 0) {
for (i = 0, len = locations.length; i < len; i++) {
alert(locations[i].address.street);
alert(locations[i].address.state);
}
} else {
alert("Your search produced no results!");
}
} else {
alert("The search request failed");
}
};
/* We perform a reverse geocode search request: translating a given
* latitude & longitude into an address
*/
var reverseGeoCodeTerm = new nokia.maps.geo.Coordinate(
52.53099,
13.38455
);
nokia.places.search.manager.reverseGeoCode({
latitude: reverseGeoCodeTerm.latitude,
longitude: reverseGeoCodeTerm.longitude,
onComplete: processResults
});
关于javascript - 如何使用诺基亚 map 获取国家或城市或州的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15215342/