djekl
11/13/2012 - 3:36 PM

<?php print_r(getCoordinates('6-8 Charlotte Square, Newcastle upon Tyne, NE1 4XF'));

php print_r(getCoordinates('6-8 Charlotte Square, Newcastle upon Tyne, NE1 4XF'));
<?php
  
    /**
     * private getCoordinates()
     */
    private function getCoordinates($address = false)
    {
        if (!$address) {
            return false;
        }

        $url  = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=';
        $url .= urlencode($address);

        $ch = curl_init();
        $timeout = 60;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        $data = curl_exec($ch);
        curl_close($ch);

        return json_decode($data);
    }
    //------------------------------------------------------------------