Skip to content

Instantly share code, notes, and snippets.

@jasonclemons
Created November 14, 2012 11:53
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 jasonclemons/4071712 to your computer and use it in GitHub Desktop.
Save jasonclemons/4071712 to your computer and use it in GitHub Desktop.
Google Maps location finder (based on https://gist.github.com/4066383)
<?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