【问题标题】:How to get the name of a country or a city or a state with Nokia Maps?如何使用诺基亚地图获取国家或城市或州的名称?
【发布时间】:2013-03-05 03:32:48
【问题描述】:

我正在使用诺基亚地图进行开发(我真的很喜欢他们的绝佳选择),但我只能使用 HTML5 获取位置(纬度和经度),但我无法说出我所在的位置:/,也许有人可以给出一个想法,如何做到这一点,非常感谢您的帮助。

【问题讨论】:

    标签: javascript geocode here-api


    【解决方案1】:

    Maps API for JavaScript 3.x

    当前的 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
    });
    

    【讨论】:

    • 非常感谢,抱歉重播晚了:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 2013-02-08
    • 1970-01-01
    • 2017-09-02
    • 2015-04-14
    • 2018-11-14
    • 1970-01-01
    相关资源
    最近更新 更多