File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 12
12
class Geolocation
13
13
{
14
14
// 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 ' ;
16
+
17
+ private $ api_key ;
18
+ private $ https ;
19
+
20
+ public function __construct ($ api_key = null , $ https = false )
21
+ {
22
+ $ this ->https = $ https ;
23
+
24
+ if ($ api_key ) {
25
+ $ this ->api_key = $ api_key ;
26
+ $ this ->https = true ;
27
+ }
28
+ }
16
29
17
30
/**
18
31
* Do call
@@ -29,14 +42,18 @@ protected function doCall($parameters = array())
29
42
}
30
43
31
44
// define url
32
- $ url = self ::API_URL . '? ' ;
45
+ $ url = ( $ this -> https ? ' https:// ' : ' http:// ' ) . self ::API_URL . '? ' ;
33
46
34
47
// add every parameter to the url
35
48
foreach ($ parameters as $ key => $ value ) $ url .= $ key . '= ' . urlencode ($ value ) . '& ' ;
36
49
37
50
// trim last &
38
51
$ url = trim ($ url , '& ' );
39
52
53
+ if ($ this ->api_key ) {
54
+ $ url .= '&key= ' . $ this ->api_key ;
55
+ }
56
+
40
57
// init curl
41
58
$ curl = curl_init ();
42
59
You can’t perform that action at this time.
0 commit comments