How to extract Postal code from V3 Google maps API

后端 未结 2 968
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 14:54

I am using the following to get a the lat-lng from a geocode..

  $latitude = $output->results[0]->geometry->location->lat;
  $longitude = $output->         


        
2条回答
  •  耶瑟儿~
    2021-02-04 15:40

    I'd say you'd need to loop through results.address_components. On each iteration check if the types array contains "postal_code". If it does, save that to a variable, and probably break out of the loop as well. Although it might be worth investigating to see if the postal_code is always in address_component[5], which would save you having to loop.

提交回复
热议问题