Is there any fairly fast php code to convert a city + country to latitude and longitude coordinates. I have a list of locations and I need to convert them to coordinates. I tried doing it in javascript, but I encountered some problems trying to get the results back to php to store it in my JSON file. So is there any efficient PHP code to do this?
Thanks.
In my app, I’m using the following function to geo-code locations using google service. The function takes one parameter –
locationto geo-code (e.g. “Boston, USA” or “SW1 1AA, United Kingdom”) and returns an associative array with Lat/Lon. If an error occurs or location cannot be determined, then it returns FALSE.Note that in many cases city + country will not be able to determine the location uniquely. For example, there are probably 100 cities named Springfield in the USA alone. Also, when passing country to a geo-coding service, make sure to put the full country name and not a 2-letter code. I found this the hard way: I was passing ‘CA’ for “Canada” and was getting strange results. Apparently, google assumed that ‘CA’ means “California”.