convert longitude and latitude to geographical direction

0

Friends I want to convert the longitude and latitude that I get with this code to geographical address

.controller('CtrlUbi', function($scope) {  
  if (navigator.geolocation) {  
    navigator.geolocation.getCurrentPosition(function(position) {  
      $scope.$apply(function() {  
        $scope.position = position;  
        console.log(position.coords.latitude);  
        console.log(position.coords.longitude);  
        console.log(position)  
      });  
    });  
  }  
});
    
asked by frd 27.09.2016 в 05:44
source

2 answers

1

Technically, position is already a geographic address.

Now, if what you need is to create an object compatible with the APIv3 of google maps, it is done this way:

var miDireccion = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

If you need to center the map on this position:

miGoogleMap.setCenter(miDireccion);

If you want to show it on the map as a marker:

var marker = new google.maps.Marker({
        position : miDireccion,
        map      : miGoogleMap,
        title    : "Mi marcador",
});

If you want to show more than one marker on the map and modify or give more information, keep an array of markers as a global variable ( var markers []; ) and insert each marker there to keep it markers.push(marker) .

    
answered by 27.09.2016 в 14:09
0

this code will help you return an address by directly obtaining latitude and longitude

if (navigator.geolocation) {
     navigator.geolocation.getCurrentPosition(function(position) {    
         $scope.createMarker(map);
         $scope.posicion_actual = {
           lat: position.coords.latitude,
           lng: position.coords.longitude
         }; 

         var geocoding ='https://maps.googleapis.com/maps/api/geocode/json?latlng=' + $scope.posicion_actual.lat + ',' + $scope.posicion_actual.lng + '&sensor=false';
         console.log(geocoding);

         $.getJSON(geocoding).done(function(location) {
            console.log(location.results[0].formatted_address);
            $scope.search_entidad = location.results[0].formatted_address;
            $scope.$digest();
         });
}
    
answered by 20.09.2017 в 04:50