During my work on a Danish website I needed to find a way to put on a map a list of Danish restaurants using only their real address (region,city,street,street number) so I start searching for the best solution to convert an address like “Danmark, Sjælland, Hørve, Dragsholm Alle 4534” to its corresponding coordinates (55.7754120, 11.3901550).
After about an hour of trying multiple solutions I concluded that Google has ,again, the best solution, at least for outside-US locations, 🙂 so I just made an extremely simple class to help me retrieve the information I needed.
I have attached here the class and a test file so you can see how it works.
I plan to develop this class in the future that’s why it requires a Google Maps API key.
Here is the test file for it, just to make an impression on how it looks like :
'; print_r($obj->getCoordinates($address )); ?>
What it returns is latitude, longitude and altitude ( only for some locations you can also get this parameter ) :
For our "Danmark, Sjælland, Hørve, Dragsholm Alle 4534" we have these data : Array ( [lat] => 55.7754120 [long] => 11.3901550 [alt] => 0 )
Note: To get the best results from Google try to format your address like this : COUNTRY, STATE/REGION, CITY, STREET_NAME STREET_NUMBER .
That’s all :), if you have questions don’t hesitate to ask.