1

我开始使用诺基亚地图 API,并且在对地址进行地理编码(获取地址的纬度/经度)时注意到了一些奇怪之处。

我在搜索“ 1348 Louvain-la-Neuve,Belgium,Belgium

它在数组中返回了一个带有地址和位置的结果;不幸的是,返回的地址似乎是法语,而不是我的自然语言环境。

返回的地址部分,返回给我一个国家值“比利时”而不是预期的“比利时”。有没有办法强制通过我的英语语言环境,而不是似乎是搜索国家的语言环境。

(我也意识到这可能不是语言环境问题,而是国家的官方名称,这对我来说仍然是一个问题,因为我用英语处理)

4

1 回答 1

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());
            }
    });

返回“比利时”

然而:

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());
                    }
                });             
            }
    });

返回“比利时”。

这是一个完整的示例(使用您自己的应用程序 ID 和令牌

<!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>
于 2013-04-08T14:32:37.483 回答