From f246be19c40bd0d80c845a54f08910e982051f1f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 24 Jun 2015 14:01:04 +1200 Subject: Handle no result from Nominatim --- .../traccar/geocode/NominatimReverseGeocoder.java | 55 ++++++++++++---------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'src/org/traccar/geocode') diff --git a/src/org/traccar/geocode/NominatimReverseGeocoder.java b/src/org/traccar/geocode/NominatimReverseGeocoder.java index 6777f5a82..27c241c66 100644 --- a/src/org/traccar/geocode/NominatimReverseGeocoder.java +++ b/src/org/traccar/geocode/NominatimReverseGeocoder.java @@ -39,35 +39,40 @@ public class NominatimReverseGeocoder extends JsonReverseGeocoder { @Override protected Address parseAddress(JsonObject json) { - Address address = new Address(); JsonObject result = json.getJsonObject("address"); - if (result.containsKey("house_number")) { - address.setHouse(result.getString("house_number")); - } - if (result.containsKey("road")) { - address.setStreet(result.getString("road")); - } - if (result.containsKey("village")) { - address.setSettlement(result.getString("village")); - } - if (result.containsKey("city")) { - address.setSettlement(result.getString("city")); - } - if (result.containsKey("state_district")) { - address.setDistrict(result.getString("state_district")); - } - if (result.containsKey("state")) { - address.setState(result.getString("state")); - } - if (result.containsKey("country_code")) { - address.setCountry(result.getString("country_code").toUpperCase()); - } - if (result.containsKey("postcode")) { - address.setPostcode(result.getString("postcode")); + if (result != null) { + Address address = new Address(); + + if (result.containsKey("house_number")) { + address.setHouse(result.getString("house_number")); + } + if (result.containsKey("road")) { + address.setStreet(result.getString("road")); + } + if (result.containsKey("village")) { + address.setSettlement(result.getString("village")); + } + if (result.containsKey("city")) { + address.setSettlement(result.getString("city")); + } + if (result.containsKey("state_district")) { + address.setDistrict(result.getString("state_district")); + } + if (result.containsKey("state")) { + address.setState(result.getString("state")); + } + if (result.containsKey("country_code")) { + address.setCountry(result.getString("country_code").toUpperCase()); + } + if (result.containsKey("postcode")) { + address.setPostcode(result.getString("postcode")); + } + + return address; } - return address; + return null; } } -- cgit v1.2.3