Skip to content

Instantly share code, notes, and snippets.

@djekl
Created November 13, 2012 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djekl/4066383 to your computer and use it in GitHub Desktop.
Save djekl/4066383 to your computer and use it in GitHub Desktop.
<?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);
}
//------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment