Created
November 13, 2012 15:36
-
-
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'));
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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