Skip to content

Commit f65d687

Browse files
author
Adam Palethorpe
committed
Added HTTPS support (required if using an api key)
1 parent a8f19e3 commit f65d687

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Geolocation.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@
1212
class Geolocation
1313
{
1414
// API URL
15-
const API_URL = 'http://maps.googleapis.com/maps/api/geocode/json';
15+
const API_URL = 'maps.googleapis.com/maps/api/geocode/json';
1616

17-
public function __construct($api_key = null)
17+
private $api_key;
18+
private $https;
19+
20+
public function __construct($api_key = null, $https = false)
1821
{
19-
$this->api_key = $api_key;
22+
$this->https = $https;
23+
24+
if ($api_key) {
25+
$this->api_key = $api_key;
26+
$this->https = true;
27+
}
2028
}
2129

2230
/**
@@ -34,7 +42,7 @@ protected function doCall($parameters = array())
3442
}
3543

3644
// define url
37-
$url = self::API_URL . '?';
45+
$url = ($this->https ? 'https://' : 'http://') . self::API_URL . '?';
3846

3947
// add every parameter to the url
4048
foreach ($parameters as $key => $value) $url .= $key . '=' . urlencode($value) . '&';

0 commit comments

Comments
 (0)