-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial class contains: (Geocode, Geolocation, searchPlace) with sett…
…ers and abstract request class.
- Loading branch information
1 parent
af0e539
commit 979a1d2
Showing
4 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
require_once 'setters.php'; | ||
|
||
final class Google extends setters | ||
{ | ||
public function Geocode() | ||
{ | ||
$this->url = 'https://maps.googleapis.com/maps/api/geocode/json?'; | ||
|
||
switch (TRUE) | ||
{ | ||
case (!empty($this->lat) && !empty($this->lng)): | ||
|
||
$this->url .= 'latlng='.$this->lat.','.$this->lng; | ||
break; | ||
|
||
case (!empty($this->address)): | ||
|
||
$this->url .= 'address='.$this->address; | ||
break; | ||
} | ||
|
||
$this->url .= '&sensor='.$this->sensor | ||
.'&key='.$this->apiKey; | ||
|
||
return $this->getData(); | ||
} | ||
|
||
public function Geolocation() | ||
{ | ||
$this->url = 'https://www.googleapis.com/geolocation/v1/geolocate?' | ||
.'query='.$this->query | ||
.'&key='.$this->apiKey; | ||
|
||
return $this->getData(); | ||
} | ||
|
||
public function searchPlace() | ||
{ | ||
$this->url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?' | ||
.'query='.$this->query | ||
.'&sensor='.$this->sensor | ||
.'&radius='.$this->radius | ||
.'&key='.$this->apiKey; | ||
|
||
return $this->getData(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
require_once 'Google.php'; | ||
|
||
define('API_KEY', 'abcdefgh1230000000'); | ||
|
||
$google = new Google(API_KEY); | ||
$google->setAddress('Bertrange, LU'); | ||
$results = $google->Geocode(); | ||
|
||
echo '<pre>'; | ||
print_r($results); | ||
|
||
/* Searching places (Using location and store name) | ||
$google = new Google(API_KEY); | ||
$google->setQuery('Walmart, 33065, USA'); | ||
$results = $google->searchPlace(); | ||
echo '<pre>'; | ||
print_r($results); | ||
#print_r($google->error); | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
abstract class request | ||
{ | ||
public $error = array(); | ||
protected $apiKey; | ||
|
||
public function __construct($apiKey) | ||
{ | ||
if (strlen($apiKey) > 38) | ||
{ | ||
$this->apiKey = $apiKey; | ||
} | ||
else | ||
{ | ||
$this->error[] = 'less than 38 character key length'; | ||
} | ||
} | ||
|
||
protected function getData() | ||
{ | ||
if (!empty($this->url)) | ||
{ | ||
if ($string = file_get_contents($this->url)) | ||
{ | ||
$results = json_decode($string); | ||
|
||
if (isset($results->results)) | ||
{ | ||
return $results->results; | ||
} | ||
elseif (isset($results)) | ||
{ | ||
return $results; | ||
} | ||
else | ||
{ | ||
return FALSE; | ||
} | ||
} | ||
else | ||
{ | ||
return FALSE; | ||
} | ||
} | ||
else | ||
{ | ||
return FALSE; | ||
} | ||
} | ||
|
||
public function showURL() | ||
{ | ||
return $this->url; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
require_once 'request.php'; | ||
|
||
class setters extends request | ||
{ | ||
protected $query; | ||
protected $address; | ||
protected $lat; | ||
protected $lng; | ||
protected $url; | ||
protected $sensor = 'true'; | ||
protected $radius = 20; | ||
|
||
public function setSensor($sensor) | ||
{ | ||
if ($sensor === TRUE || $sensor == 'true') | ||
{ | ||
$this->sensor = 'true'; | ||
} | ||
if ($sensor === FALSE || $sensor == 'false') | ||
{ | ||
$this->sensor = 'false'; | ||
} | ||
} | ||
|
||
public function setQuery($query) | ||
{ | ||
$this->query = urlencode($query); | ||
} | ||
|
||
public function setRadius($radius) | ||
{ | ||
if ((int) $radius > 0) | ||
{ | ||
$this->radius = $radius; | ||
} | ||
} | ||
|
||
public function setAddress($address) | ||
{ | ||
$this->address = urlencode($address); | ||
} | ||
|
||
public function setLatLng($lat, $lng) | ||
{ | ||
$this->lat = $lat; | ||
$this->lng = $lng; | ||
} | ||
|
||
public function setLat($lat) | ||
{ | ||
$this->lat = $lat; | ||
} | ||
|
||
public function setLng($lng) | ||
{ | ||
$this->lng = $lng; | ||
} | ||
} |