Skip to content

Instantly share code, notes, and snippets.

@tojibon
Created September 10, 2015 10:51
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 tojibon/bc94e144515b43e032a9 to your computer and use it in GitHub Desktop.
Save tojibon/bc94e144515b43e032a9 to your computer and use it in GitHub Desktop.
Get location info by google latitude and longitude via Google Map API and CURL
<?php
/*
Get location info by google latitude and longitude via Google Map API and CURL
You may need to change the proxy ip:port and auth username:pass or keep them empty.
*/
/*
*
* @ param string $url as 'http://maps.google.com'; Page url location which you want to fetch
* @ param string $proxy [optional] as '[proxy IP]:[port]'; Proxy address and port number
* which you want to use
* @ param string $userpass [optional] as '[username]:[password]'; Proxy authentication
* username and password
* @ return a url page html content
*
* */
function curl($url, $proxy='', $userpass='') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(!empty($proxy))
curl_setopt($ch, CURLOPT_PROXY, $proxy);
if(!empty($userpass))
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $userpass);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$latitude = "34.03679";
$longitude = "-118.263248";
$map_api_url = "http://maps.googleapis.com/maps/api/geocode/json?latlng={$latitude},{$longitude}&sensor=false";
$proxy = '66.xxx.156.xxx:xxxx';
$userpass = '65H4xxxx7YR:xxxx';
$address_content = curl($map_api_url, $proxy, $userpass);
$address_info = json_decode($address_content);
print_r($address_info);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment