Skip to content

Instantly share code, notes, and snippets.

@wayneashleyberry
Created November 26, 2012 11:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayneashleyberry/4147721 to your computer and use it in GitHub Desktop.
Save wayneashleyberry/4147721 to your computer and use it in GitHub Desktop.
maps api latlng
<?php
function get_latlng ($address)
{
// api key
$key = '';
// maps geocode api request
$url = "https://maps.googleapis.com/maps/api/geocode/json";
$query = "?address=" . urlencode($address) . "&sensor=false";
$ch = curl_init();
// Set query data here with the URL
curl_setopt($ch, CURLOPT_URL, $url . $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
// save response
$results = $json->results;
if (!empty($results))
{
return $results[0];
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment