Sometimes you need to get exact location by address entered by user on your website. Google Maps API offers a service that will return exact coordinate by the request you send it. See following snippet to see how to get coordinates from postcode or address by using Google Maps API.
$address = '124 Norfolk Street, Glasgow, United Kingdom'; $response = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=true'); $response = json_decode($response); echo 'Latitude:' . $response->results->geometry->location->lat; echo 'Longitude:' . $response->results->geometry->location->lng;
I hope you enjoy it and make useful scripts for your project!