Created
November 26, 2012 11:20
-
-
Save wayneashleyberry/4147721 to your computer and use it in GitHub Desktop.
maps api latlng
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 | |
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