I'm getting city name from a 3rd party API. That API doesn't return normalized city name. For example, sometimes its San Francisco
, sometime its San Francisco, CA
, sometimes its San Francisco, USA
. I dont need street address etc.. I just need to normalize the city name to be something uniform. I'm looking for a service that could help me with this requirement.
P.S: Its not mobile app, its web app and the location doesn't come from the browser.
If it's consistent with the city names, you could scan the string and check if there's a comma and if there is ignore anything after
You can use the Google Maps API to get normalized address:
1) Get result from: https://maps.googleapis.com/maps/api/geocode/json?address=san_francisco
2) Extract the city name from
$data['results'][0]['address_components'][0]['long_name']
.Source: https://developers.google.com/maps/documentation/geocoding/intro