home / blog

Tag Archives: geocode

Reverse geocode using PHP

function getPostcode($lat, $lng) { $returnValue = NULL; $ch = curl_init(); $url = “http://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&sensor=false”; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); $json = json_decode($result, TRUE); if (isset($json[‘results’])) { foreach ($json[‘results’] as $result) { foreach ($result[‘address_components’] as $address_component) { $types … Continue reading

Posted in geek | Tagged , | Leave a comment