From 30999d23513103e6bde2d4db34fa86b39ee117e7 Mon Sep 17 00:00:00 2001 From: theirix Date: Sun, 8 Jan 2017 17:07:32 +0300 Subject: [PATCH] Support OLC in SearchCore --- .../src/net/osmand/search/core/SearchCoreFactory.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java index 9ceb6b7d38..71bd0873c2 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java @@ -1,5 +1,6 @@ package net.osmand.search.core; +import com.google.openlocationcode.OpenLocationCode; import com.jwetherell.openmap.common.LatLonPoint; import com.jwetherell.openmap.common.UTMPoint; @@ -1031,6 +1032,15 @@ public class SearchCoreFactory { LatLon parseLocation(String s) { s = s.trim(); + // detect OLC first + // avoid throwing exceptions by carefully checking exceptions + if (s.length() > 0 && OpenLocationCode.isValidCode(s)) { + OpenLocationCode olc = new OpenLocationCode(s); + if (olc.isFull()) { + OpenLocationCode.CodeArea codeArea = olc.decode(); + return new LatLon(codeArea.getCenterLatitude(), codeArea.getCenterLongitude()); + } + } if(s.length() == 0 || !(s.charAt(0) == '-' || Character.isDigit(s.charAt(0)) || s.charAt(0) == 'S' || s.charAt(0) == 's' || s.charAt(0) == 'N' || s.charAt(0) == 'n'