forked from SpaghettiCodeStudios/HowMuchWithTax
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseGeocode.php
More file actions
33 lines (24 loc) · 799 Bytes
/
Copy pathreverseGeocode.php
File metadata and controls
33 lines (24 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
header("Access-Control-Allow-Origin: *");
class Location{
public function getZip($latlng){
$urlBase = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=';
$mapsApiKey = '&key=[Insert Google maps APIkey here]';
$constructedUrl = $urlBase.$latlng.$mapsApiKey;
echo $this->getJSON($constructedUrl);
}
private function getJSON($requestUrl){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$requestUrl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);
$json = curl_exec($ch);
if(!$json) {
echo curl_error($ch);
}
curl_close($ch);
return $json;
}
}
$location = new Location();
$location->getZip($_GET['latlng']);