我开始使用诺基亚地图API,并注意到地理编码地址时的一些奇怪之处(获取地址的纬度/经度)。
我在寻找“ 1348 Louvain-la-Neuve,比利时,比利时”
它在数组中返回了一个带有地址和位置的结果;不幸的是,返回的地址似乎是法语,而不是我自然的英语语言环境。
返回的地址部分,返回一个国家/地区值“ Belgique ”而不是预期的“比利时”。有没有办法强制通过我的英语语言环境,而不是似乎是搜索国家的地区。
(我也意识到这可能不是一个地方问题,而是国家的官方名称,这对我来说仍然是一个问题,因为我用英语交易)
答案 0 :(得分:0)
这是一个错误(票号:JSLA-3608)。应该是添加nokia.Settings.set("defaultLanguage", "en-GB");
改变地理编码请求的区域设置的情况,但它看起来像地理编码功能没有将区域设置传递给地理编码服务。有趣的是,reverseGeocoding服务确实正确传递了语言环境,因此可以使用变通方法来获取首选语言环境:
searchManager.geoCode({
searchTerm: "1348 Louvain-la-Neuve,Belgium,Belgium",
onComplete: function (data, requestStatus, requestId) {
processResults(data, requestStatus, requestId);
map.zoomTo(addressesContainer.getBoundingBox());
}
});
返回“Belgique”
,而:
searchManager.geoCode({
searchTerm: "1348 Louvain-la-Neuve,Belgium,Belgium",
onComplete: function (data, requestStatus, requestId) {
nokia.places.search.manager.reverseGeoCode({
latitude: data.location.position.latitude,
longitude: data.location.position.longitude,
onComplete: function (data, status) {
processResults(data, requestStatus, requestId);
map.zoomTo(addressesContainer.getBoundingBox());
}
});
}
});
返回“比利时”。
以下是完整示例(使用您自己的app id and token)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9; IE=EmulateIE10;"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Nokia Maps API for JavaScript Example: Addresses</title>
<meta name="description" content="Geocode multiple addresses and display them using standard markers and infobubbles"/>
<meta name="keywords" content="addresses, services, geocode, reverse, geocode"/>
<!-- For scaling content for mobile devices, setting the viewport to the width of the device-->
<meta name=viewport content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<!-- Styling for example container (NoteContainer & Logger) -->
<link rel="stylesheet" type="text/css" href="http://developer.here.com/apiexplorer/examples/templates/js/exampleHelpers.css"/>
<!-- By default we add ?with=all to load every package available, it's better to change this parameter to your use case. Options ?with=maps|positioning|places|placesdata|directions|datarendering|all -->
<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.4/jsl.js?with=all"></script>
<!-- JavaScript for example container (NoteContainer & Logger) -->
<style type="text/css">
html {
overflow:hidden;
}
body {
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
height: 100%;
position: absolute;
}
#mapContainer {
width: 100%;
height: 100%;
left: 0;
top: 0;
position: absolute;
}
</style>
</head>
<body>
<div id="mapContainer"></div>
<div id="uiContainer"></div>
<script type="text/javascript" id="exampleJsSource">
/* Set authentication token and appid
* WARNING: this is a demo-only key
* please register on http://api.developer.nokia.com/
* and obtain your own developer's API key
*/
nokia.Settings.set("appId", "APP ID);
nokia.Settings.set("authenticationToken", "TOKEN");
nokia.Settings.set("defaultLanguage", "en-GB");
// Get the DOM node to which we will append the map
var mapContainer = document.getElementById("mapContainer");
// We create a new instance of InfoBubbles bound to a variable so we can call it later on
var infoBubbles = new nokia.maps.map.component.InfoBubbles();
// Create a map inside the map container DOM node
var map = new nokia.maps.map.Display(mapContainer, {
// initial center and zoom level of the map
center: [52.51, 13.4],
zoomLevel: 10,
components:[
// We add the behavior component to allow panning / zooming of the map
new nokia.maps.map.component.Behavior(),
infoBubbles
]
});
var location2,
// We will put our address markers into this container zo we can zoom in to the markers
addressesContainer = new nokia.maps.map.Container(),
marker,
searchCenter = new nokia.maps.geo.Coordinate(52.51, 13.4),
searchManager = nokia.places.search.manager;
map.objects.add(addressesContainer);
var processResults = function (data, requestStatus, requestId) {
// Data is instance of nokia.places.objects.Place
var location = data.location;
// Ensure that we our request came back with valid result
if (requestStatus == "OK") {
// Create a new marker on the found location
marker = new nokia.maps.map.StandardMarker(location.position);
// Add marker to its container so it will be render
addressesContainer.objects.add(marker);
marker.$address = location.address;
marker.$label = data.name;
}
};
/*
searchManager.geoCode({
searchTerm: "1348 Louvain-la-Neuve,Belgium,Belgium",
onComplete: function (data, requestStatus, requestId) {
processResults(data, requestStatus, requestId);
map.zoomTo(addressesContainer.getBoundingBox());
}
}); */
searchManager.geoCode({
searchTerm: "1348 Louvain-la-Neuve,Belgium,Belgium",
onComplete: function (data, requestStatus, requestId) {
nokia.places.search.manager.reverseGeoCode({
latitude: data.location.position.latitude,
longitude: data.location.position.longitude,
onComplete: function (data, status) {
processResults(data, requestStatus, requestId);
map.zoomTo(addressesContainer.getBoundingBox());
}
});
}
});
addressesContainer.addListener("click", function (evt) {
var marker = evt.target,
address = marker.$address,
label = marker.$label;
if (marker instanceof nokia.maps.map.Marker) {
infoBubbles.openBubble(label, marker.coordinate);
}
});
</script>
</body>
</html>