Linked Questions

Popular Questions

I would like to be able to identify any and all valid geographical locations from any given string using the MapBox geocoding API.

Example string:

5 things to avoid when venturing to Thailand and Amsterdam

The most obvious solution is to first split the string into an array of sub strings and pass each of those, one by one, to the geocode(); function:

$string = "5 things to avoid when venturing to Thailand and Amsterdam";
$words = explode(" ",$string);
 foreach($words as $word) {
     $res = $mapbox->geocode($word);
     print_r($res->getData());
 }

and then you can determine if it's a valid location by analysing what is returned from the $res->getData(); function.

This seems like a very long process if there's a lot of strings that need to be tested. It also does not account for places that contain spaces like Hong Kong.

So, is there any other way using the MapBox geocoding API or any other API that allows me to identify any and all locations in a given string more efficiently?

Related Questions