从自动完成getPlace()调用返回的Placeresult对象缺少几个属性

时间:2012-03-19 22:25:08

标签: google-maps autocomplete google-maps-api-3 google-places-api

调用autocomplete.getPlace()时,返回的PlaceResult对象现在缺少formatted_phone_number,international_phone_number,rating和网站属性。当我执行place对象的console.log时,这是返回的内容:

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

注意Placeresult中上面提到的属性如何不再存在。这些属性肯定会在上周左右的autocomplete.getPlace()调用中显示在Placeresult中。来自service.getDetails()的Placeresult对象正确返回Places V3 API中提到的所有属性,但是.getPlace()调用现在缺少这些属性,尽管引用了相同的Placeresult。知道为什么现在缺少这些属性吗?

代码:

  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);

1 个答案:

答案 0 :(得分:0)

Places-API仍处于试验阶段,所以当你上周说出手机号码时,他们可能会改变一些东西。

但是,你是对的,你得到的是placeSearchResponse而不是placeDetailsResponse(应该是什么)。