Created
November 14, 2012 11:53
-
-
Save jasonclemons/4071712 to your computer and use it in GitHub Desktop.
Google Maps location finder (based on https://gist.github.com/4066383)
This file contains hidden or 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 | |
class GoogleMaps { | |
private function find($location = null) { | |
if ($location == null) { | |
return false; | |
} | |
$uri_parts = array( | |
'q' => urlencode($location), | |
'output' => 'json', | |
'oe' => 'utf8', | |
'source' => 'false' | |
); | |
$uri = 'https://maps.google.com/maps/geo?' . http_build_query($uri_parts, '&', null); | |
$ci = curl_init(); | |
curl_setopt($ci, CURLOPT_URL, $uri); | |
curl_setopt($ci, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ci, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($ci, CURLOPT_TIMEOUT, 10); | |
$result = curl_exec($ci); | |
curl_close($ci); | |
$result = json_decode($result, true); | |
if ($result['Status']['code'] == 200) { | |
return $result; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment