Question

I'm developing with Nokia Maps (a wonderful option I really love them) but I'm only able to get the location (latitude and longitude) with HTML5 but I can't the name where I am :/, maybe somebody could give an idea, how to do it, thank you very mach for your help.

Was it helpful?

Solution

Maps API for JavaScript 3.x

The current 3.x JavaScript API offers a thin wrapper around the REST Geocoder API. You need to make a ReverseGeocode search, and then extract the data from the Location object(s) found in the result.

A fully working reverse geocoding example can be found here, but the important bit (getting the address) can be see below:

    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 (deprecated)

With the recently deprecated 2.x JavaScript API, again you need to make a ReverseGeocode search, and then extract the data from the Address object found in the result.

The code is a bit longer, but the important bit (getting the address) can be seen below:

// 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
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top