2

为什么地址组件是 Indian Reservation 时没有返回类型?它只是返回如下所示,并且由于没有类型,因此在尝试对返回 Indian Reservation 的地址进行地理编码时会导致错误。

<address_component>
 <long_name>Hopi Indian Reservation</long_name>
 <short_name>Hopi Indian Reservation</short_name>
</address_component>

示例地址:HWY 160 & HWY 264 Tuba City, AZ 86045

或者

HWY 160 和 HWY 163 卡延塔,亚利桑那州 86033

4

1 回答 1

4

I guess the documentation about Address Component Types is a bit too subtle as to (not mentioning) the fact that there is no guarantee that the types[] array will always contain something, or that hese types may also be returned within address_components[] arrays ... or may not.

Your example reproduces this behavior pretty well:

http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=Hopi%20Indian%20Reservation

The types[] array is empty for the first result and its first address component.

Short term, I think your (and everybody's) code should be ready to accept empty types[] arrays. Long term, I'd agree it'd be better to give every result at least one type. For the specific case of indian reservations, I've no idea which one (if any) of the available ones would make sense. Maybe one of...

  • political indicates a political entity. Usually, this type indicates a polygon of some civil administration.
  • colloquial_area indicates a commonly-used alternative name for the entity.
  • park indicates a named park.
  • point_of_interest indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty."

If anyone has a clear idea how to classify these in the available Address Component Types, please file a feature request for the Geocoding API ;)

于 2012-01-26T07:05:52.893 回答