2

I want to get place details using place_id, get_place details I am using Angular_google_map, I am using following code but this is not giving place details as above but I am getting different format.

    var map_obj=$scope.map.control.getGMap();
    var service = new google.maps.places.PlacesService(map_obj);

    $scope.$watch(function() {
      return $scope.place_id;
    }, function(place_id) {
      if (!place_id) {
        return;
      }
      service.getDetails({ placeId: place_id }, function(place, status) {
        console.log('place='+place);
        $scope.places=place;
      });
    });      

Above code is giving following format but I want in different format, please see required format, you can see that geometry format is different from required format. How to get required format.

Place_format

Object {address_components: Array[5], adr_address: "<span class="extended-address">HSR Layout</span>, …a</span>, <span class="country-name">India</span>", formatted_address: "HSR Layout, Bengaluru, Karnataka, India", geometry: Object, icon: "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"…}
address_components: Array[5]
adr_address: "<span class="extended-address">HSR Layout</span>, <span class="locality">Bengaluru</span>, <span class="region">Karnataka</span>, <span class="country-name">India</span>"
formatted_address: "HSR Layout, Bengaluru, Karnataka, India"
geometry: Object
location: M
lat: function (){return a}
lng: function (){return b}
__proto__: M
viewport: Pd
__proto__: Object
html_attributions: Array[0]
icon: "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"
id: "cfeef42cd5db5d4c2a55fc842fcdd712fb1092ad"
name: "HSR Layout"
place_id: "ChIJzW7cv5EUrjsRecj7OYRxMvI"
reference: "CpQBhQAAAC4IfuHnzBloeWfXk8AR4aGPBPIqwAMaIokCX5Ealqo33bGUw5PeRbkUjPvzy_5qqHryCpIz8TSWp0KidBuQ9res84IYoUTnCwlI831HQvHDmPf3uwzui4Bz5GK8mimTPxm4PEOOIpzXpV5ruF9zqJz2L0nMRSuSQJKVcbCSiLOCL4ijmehb5ggm-T5BBkYR6BIQzGX0fHP5x2_7NuUiJMUMFxoUy792_TmWmqOTrImnczW1TIwxwc0"
scope: "GOOGLE"
types: Array[3]
url: "https://maps.google.com/maps/place?q=HSR+Layout,+Bengaluru,+Karnataka,+India&ftid=0x3bae1491bfdc6ecd:0xf232718439fbc879"
vicinity: "HSR Layout"
__proto__: Object
Neelabh Singh
  • 2,600
  • 12
  • 51
  • 88
  • Sorry, I don't understand this question, but I hope this information helps: For an example of using `PlacesService.getDetails` look at https://developers.google.com/maps/documentation/javascript/examples/place-details. The `geometry` property of `PlaceResult` objects is documented at https://developers.google.com/maps/documentation/javascript/reference#PlaceGeometry. – spiv Nov 02 '15 at 06:48
  • possible duplicate of [Multiple markers on google maps using json and placeid](http://stackoverflow.com/questions/31804984/multiple-markers-on-google-maps-using-json-and-placeid) – geocodezip Feb 10 '16 at 14:32

1 Answers1

2

I was having trouble trying to do this too and I just figured it out. The easiest way is to use an instance of PlaceService:

var placesService = new google.maps.places.PlacesService(map);

placesService.getDetails(
    {placeId: 'reallylongstringgoeshere'},
    function(results, status) {
        console.log(status);
        console.log(results); 
    }
);

Check out their docs with an example.