Return Location ID only with Latitude and Longitude - Google Maps Javascript API

Asked

Viewed 190 times

1

Good evening, my question refers to the following case:

I am working with the API of google maps V3, and I use services such as Places, Geocoder and Matrix Distance. However I have a huge problem to return the ID of the current location of the user (returned using the maps Geolocation), however it returns me only the Latitude and Longitude of the place, or I am not knowing return other information.

        if (navigator.geolocation) { 
      navigator.geolocation.getCurrentPosition(function(position) {
        posAtual = { // recebe ltd e lngt
          lat: position.coords.latitude,
          lng: position.coords.longitude
        };

        var openedMarker = posAtual.lat + "<br>" + posAtual.lng;


      var markerAtual = addMarker({coords:posAtual, content:openedMarker}); // define o local do marker

      map.setCenter(posAtual); // centraliza posição atual se permitido pelo browser

      }, function() {
        handleLocationError(true, markerAtual, map.getCenter()); // se der erro volta pra localização antiga

      });
    return true;
    } else {
      // Browser doesn't support Geolocation ou NÃO foi aceito pelo user
      handleLocationError(false, markerAtual, map.getCenter());

    return false;
    }
    function handleLocationError(browserHasGeolocation, infoWindow, pos) { //Erro que sera exibido caso falhe
    infoWindow.setPosition(pos);
    infoWindow.setContent(browserHasGeolocation ?
                          'Error: The Geolocation service failed.' :
                          'Error: Your browser doesn\'t support geolocation.');

}

This is the code I use to find the current position, I’ve tried to search in the google documentation or even here in the OS, but without much success.

The API returns the Local ID whenever it is searched, in this case, with a place autocomplete field. But it doesn’t happen when searching for a Latitude/Longitude coordinate.

Thank you for your attention.

  • 1

    Could put an example url?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.