1

I am using the Google direction API to get itineraries based on points that can be cities only (not addresses, countries, or any POI).

I would like to parse the city name out of the response, but the API return a somewhat cumbersome string that includes postcodes, states, countries, etc. Nevertheless, it appears that this format is not always the same, which makes it somewhat dangerous to try to get a sub-string out it. Example:

link 1 This call returns Australian locations names with postcodes, states, and country.

"start_address": "Albury NSW 2640, Australia",
"end_address": "Bendigo VIC 3550, Australia",

link 2 this call returns French locations that have no region nor postcode.

start_address": "Reims, France",
end_address": "Metz, France",

Any thoughts?

Yann
  • 877
  • 14
  • 25
  • Note: here is the temporary solution that relies on parsing the string : `$end_address = $GoogleResponseArray['routes'][0]['legs'][$x]['end_address']; $end_address = explode(",",$end_address)[0]; $end_address = explode(" ",$end_address)[0];` – Yann Sep 27 '14 at 12:42

1 Answers1

1

The only known solution relies on parsing the string :

$end_address = $GoogleResponseArray['routes'][0]['legs'][$x]['end_address']; $end_address = explode(",", $end_address)[0]; $end_address = explode(" ", $end_address)[0];

Yann
  • 877
  • 14
  • 25