Placeresult object returned from autocomplete getPlace () skips multiple properties

Calling autocomplete.getPlace () returns the returned PlaceResult object without the name formatted_phone_number, international_phone_number, rating, and website properties. When I do console.log of the place object, this is what is returned:

Object
address_components: Array[8]
formatted_address: "Google Sydney, 5/48 Pirrama Rd, Pyrmont NSW 2009, Australia"
geometry: Object
html_attributions: Array[0]
icon: "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"
id: "20074bf275d0d9476ed98e17445c8c19531e0c20"
name: "Google Sydney"
reference: "CnRlAAAASdbJCc7CCRHiL1gb7Z7BwJ9dLXhM16AexHOmugvvuC9t4o_RqKpgrq57CkIjS_YO7iCHtmypMjOFCkhc4zBGF882PHQW4Bv2rHEvePPfIrjWxT4VjYF7N-5SveVoPT7xe-jfWzH7YZDWeDxKyYFE2xIQJQb58Lr_dkmCmYVATfeObBoU1SmGG30mBXMR4TavRMo9XZNX8L4"
types: Array[2]
url: "http://maps.google.com/maps/place?ftid=0x6b12ae37b47f5b37:0x8eaddfcd1b32ca52"
vicinity: "Pyrmont"
__proto__: Object

      

Note that the properties mentioned above in Placeresult no longer exist. These properties were definitely showing up in Placeresult from a call to autocomplete.getPlace () in the last week or so. Placeresult objects from service.getDetails () correctly return all the properties mentioned in the Places V3 API, however the call to .getPlace () now skips these attributes despite referencing the same Placeresult. Any idea why these properties are missing now?

code:

  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-33.8688, 151.2195),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById('map_canvas'),
      mapOptions);

    var input = document.getElementById('searchTextField');
    var autocomplete = new google.maps.places.Autocomplete(input);

    autocomplete.bindTo('bounds', map);

    var infowindow = new google.maps.InfoWindow();
    var marker = new google.maps.Marker({
      map: map
    });

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      infowindow.close();
      var place = autocomplete.getPlace();
      console.log(place);
      if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
      } else {w
        map.setCenter(place.geometry.location);
        map.setZoom(17);  // Why 17? Because it looks good.
      }

      var image = new google.maps.MarkerImage(
          place.icon,
          new google.maps.Size(71, 71),
          new google.maps.Point(0, 0),
          new google.maps.Point(17, 34),
          new google.maps.Size(35, 35));
      marker.setIcon(image);
      marker.setPosition(place.geometry.location);

      var address = '';
      if (place.address_components) {
        address = [(place.address_components[0] &&
                    place.address_components[0].short_name || ''),
                   (place.address_components[1] &&
                    place.address_components[1].short_name || ''),
                   (place.address_components[2] &&
                    place.address_components[2].short_name || '')
                  ].join(' ');
      }

      infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
      infowindow.open(map, marker);
    });

    // Sets a listener on a radio button to change the filter type on Places
    // Autocomplete.
    function setupClickListener(id, types) {
      var radioButton = document.getElementById(id);
      google.maps.event.addDomListener(radioButton, 'click', function() {
        autocomplete.setTypes(types);
      });
    }

    setupClickListener('changetype-all', []);
    setupClickListener('changetype-establishment', ['establishment']);
    setupClickListener('changetype-geocode', ['geocode']);
  }
  google.maps.event.addDomListener(window, 'load', initialize);

      

+3


source to share


1 answer


The Places-API is still experimental, so when you say you got phone numbers last week, they might have changed something.



But, however, you are correct, what you get is placeSearchResponse and not placeDetailsResponse (which it should be).

0


source







All Articles