From 1633b83e91467166d7504b400afa39e5c87ba6cf Mon Sep 17 00:00:00 2001 From: vitalisator Date: Mon, 3 Aug 2015 10:18:52 +0200 Subject: [PATCH 1/3] add support for Google geocoding API key --- includes/polling/functions.inc.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 243fe77dc..79489ed7a 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -430,8 +430,13 @@ function location_to_latlng($device) { switch ($config['geoloc']['engine']) { case "google": default: - d_echo("Google geocode engine being used\n"); - $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location"; + d_echo("Google geocode engine being used\n"); + if (!empty($api_key = ($config['geoloc']['api_key']))) { + d_echo("Use Google API key: $api_key\n"); + $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location&key=$api_key"; + } else { + $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location"; + } break; } $curl_init = curl_init($api_url); From 7e2b8f72f186c67f502eafe23cbbd5a3c842441e Mon Sep 17 00:00:00 2001 From: vitalisator Date: Mon, 3 Aug 2015 10:29:08 +0200 Subject: [PATCH 2/3] add google gecode API key support. Config variable: $config[geoloc][api_key] = "place_your_key_here" --- includes/polling/functions.inc.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 79489ed7a..a231ababb 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -430,13 +430,13 @@ function location_to_latlng($device) { switch ($config['geoloc']['engine']) { case "google": default: - d_echo("Google geocode engine being used\n"); - if (!empty($api_key = ($config['geoloc']['api_key']))) { - d_echo("Use Google API key: $api_key\n"); - $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location&key=$api_key"; - } else { - $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location"; - } + d_echo("Google geocode engine being used\n"); + if (!empty($api_key = ($config['geoloc']['api_key']))) { + d_echo("Use Google API key: $api_key\n"); + $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location&key=$api_key"; + } else { + $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location"; + } break; } $curl_init = curl_init($api_url); From 6290019623475903514e2dbe7bf8b85ff46a0cc9 Mon Sep 17 00:00:00 2001 From: vitalisator Date: Mon, 3 Aug 2015 16:56:57 +0200 Subject: [PATCH 3/3] make the code clear --- includes/polling/functions.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index a231ababb..4eb12609b 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -431,7 +431,8 @@ function location_to_latlng($device) { case "google": default: d_echo("Google geocode engine being used\n"); - if (!empty($api_key = ($config['geoloc']['api_key']))) { + $api_key = ($config['geoloc']['api_key']); + if (!empty($api_key)) { d_echo("Use Google API key: $api_key\n"); $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location&key=$api_key"; } else {