2

I want to find the location name which user select on map. Currently I am getting latitude and longitude both. But unable to get the location name.

I am using angularJS and angular-google-maps 2.1.5.

Here is the html.

<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" events="map.events">

</ui-gmap-google-map>

JS :

$scope.map = {
      center: {
        latitude: 21.0000,
        longitude: 78.0000
      },
      zoom: 4,
      events: {
        click: function(mapModel, eventName, originalEventArgs,ok) {
          var e = originalEventArgs[0]; 

            objOneDevice.dev_latitude = e.latLng.lat();
            objOneDevice.dev_longitude = e.latLng.lng();

            $scope.templatedInfoWindow.show = true;

        }
      }
    };
    $scope.options = {
      scrollwheel: true
    };

Anything is appreciated.

3 Answers 3

12

Here what I have done using Reverse geocoding.

$scope.map = {
      center: {
        latitude: 21.0000,
        longitude: 78.0000
      },
      zoom: 4,
      events: {
        click: function(mapModel, eventName, originalEventArgs,ok) {
          var e = originalEventArgs[0]; 

            var geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(e.latLng.lat(), e.latLng.lng());

            geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (results[1]) {

                            console.log(results[1].formatted_address); // details address
                        } else {
                            console.log('Location not found');
                        }
                    } else {
                        console.log('Geocoder failed due to: ' + status);
                    }
                });


        }
      }
    };
Sign up to request clarification or add additional context in comments.

1 Comment

Why don't you accept your own answer as a solution ?
1

Given Latitude/Longitude object you can map location to approximate address using Google Map API. You can use the Geocoding API for mapping locations to addresses and addresses to locations.

Geocoder.geocode( { 'latLng': latLngObject }, callbackFn);

Here is the link for Google Map API for Geocoding.

1 Comment

Is there any other way to achieve using angular way?
1

Try these links https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse?csw=1

Use the Geocoding API for mapping locations to addresses and addresses to locations. http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

Geocoder.geocode( { 'latLng': latLngObject }, callback);

http://wbyoko.co/angularjs/angularjs-google-maps-components.html

Hope it helps!!!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.