angularJS find the location/place name using angular google map
Solution 1
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);
}
});
}
}
};
Solution 2
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!!!
Solution 3
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.
Comments
-
RIYAJ KHAN almost 2 years
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
andangular-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.
-
RIYAJ KHAN over 8 yearsIs there any other way to achieve using angular way?
-
Sampath about 8 yearsWhy don't you accept your own answer as a solution ?