2013-03-05 75 views

回答

3

地圖API爲JavaScript 3.X

目前3.x中的JavaScript API提供圍繞REST Geocoder API瘦包裝。您需要進行ReverseGeocode搜索,然後從結果中找到的Location對象中提取數據。

了一個有效的反向地理編碼的例子可以發現here,但重要的一點(獲取地址)可以在下面看到:

對JavaScript 2.X(不建議使用)

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!'); 
    } 
); 
} 

地圖API

最近已棄用 2.x JavaScript API,您需要再次進行ReverseGeocode搜索,然後從Address對象f中提取數據f得出的結果。

的代碼是有點長,但最重要的一點(獲取地址),可以看到下面:

// 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 
}); 
+0

非常感謝你,重播遲到抱歉:/ – 2013-03-12 16:31:43

相關問題