From e8f5028cab5d95792c9df34824b7c76bfa9c6222 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 15 Mar 2016 10:56:23 +1300 Subject: Support key for Google geocoder (fix #1781) --- src/org/traccar/Context.java | 6 +++++- src/org/traccar/geocode/GoogleReverseGeocoder.java | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index 55561b921..e87f78d20 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -148,7 +148,11 @@ public final class Context { reverseGeocoder = new FactualReverseGeocoder(url, key, cacheSize); break; default: - reverseGeocoder = new GoogleReverseGeocoder(cacheSize); + if (key != null) { + reverseGeocoder = new GoogleReverseGeocoder(key, cacheSize); + } else { + reverseGeocoder = new GoogleReverseGeocoder(cacheSize); + } break; } } diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java index f1c27c5d3..be863718b 100644 --- a/src/org/traccar/geocode/GoogleReverseGeocoder.java +++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java @@ -29,6 +29,10 @@ public class GoogleReverseGeocoder extends JsonReverseGeocoder { super("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f", cacheSize); } + public GoogleReverseGeocoder(String key, int cacheSize) { + super("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=" + key, cacheSize); + } + @Override public Address parseAddress(JsonObject json) { JsonArray results = json.getJsonArray("results"); -- cgit v1.2.3