From 29215cdc44ff877f6121aec598b9829eab539485 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 11 Dec 2018 21:20:21 +0100 Subject: [PATCH] Fix #6110 --- .../main/java/net/osmand/osm/edit/Way.java | 1 - .../net/osmand/util/GeoPointParserUtil.java | 30 ++++++++++++++----- .../osmand/util/GeoPointParserUtilTest.java | 13 ++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/edit/Way.java b/OsmAnd-java/src/main/java/net/osmand/osm/edit/Way.java index f55667b1ed..ba71f7645a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/edit/Way.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/edit/Way.java @@ -194,7 +194,6 @@ public class Way extends Entity { } if (nodeIds != null) { nodeIds.reverse(); - ; } } } diff --git a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java index 9eea38d32e..f6ac336605 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -526,11 +526,20 @@ public class GeoPointParserUtil { if (params.containsKey("z")) { zmPart = params.get("z"); } - String[] vls = silentSplit(path, ","); + String[] vls = null; + if(path.contains("@")) { + path = path.substring(path.indexOf("@") + 1); + if(path.contains(",")) { + vls = silentSplit(path, ","); + } + } + if(vls == null) { + vls = silentSplit(path, ","); + } if (vls.length >= 2) { - double lat = parseSilentDouble(vls[0]); - double lon = parseSilentDouble(vls[1]); + double lat = parseSilentDouble(vls[0], Double.NaN); + double lon = parseSilentDouble(vls[1], Double.NaN); int zoom = GeoParsedPoint.NO_ZOOM; if (vls.length >= 3 || zmPart.length() > 0) { if (zmPart.length() == 0) { @@ -543,7 +552,9 @@ public class GeoPointParserUtil { } zoom = parseZoom(zmPart); } - return new GeoParsedPoint(lat, lon, zoom); + if(!Double.isNaN(lat) && !Double.isNaN(lon)) { + return new GeoParsedPoint(lat, lon, zoom); + } } return new GeoParsedPoint(URLDecoder.decode(opath)); } @@ -566,13 +577,17 @@ public class GeoPointParserUtil { } private static double parseSilentDouble(String zoom) { + return parseSilentDouble(zoom, 0); + } + + private static double parseSilentDouble(String zoom, double vl) { try { if (zoom != null) { return Double.valueOf(zoom); } } catch (NumberFormatException e) { } - return 0; + return vl; } private static int parseSilentInt(String zoom) { @@ -739,8 +754,9 @@ public class GeoPointParserUtil { @Override public String toString() { - return isGeoPoint() ? "GeoParsedPoint [lat=" + lat + ", lon=" + lon + ", zoom=" + zoom - + ", label=" + label + "]" : "GeoParsedPoint [query=" + query; + return isGeoPoint() ? + String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%d, label=%s]", lat, lon, zoom, label) : + String.format("GeoParsedPoint [query=%s]",query); } } } diff --git a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java index 14c76a0f2b..05138ea91e 100644 --- a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java +++ b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java @@ -19,6 +19,19 @@ public class GeoPointParserUtilTest { GeoParsedPoint test = GeoPointParserUtil.parse("geo:0,0?q=86HJV99P%2B29"); Assert.assertEquals(test.getQuery(), "86HJV99P+29"); } + + @Test + public void testGoogleMaps() { + // https://www.google.com/maps?daddr=Bahnhofplatz+3,+7000+Chur@46.853582,9.529903 + GeoParsedPoint actual = GeoPointParserUtil.parse( + "https://www.google.com/maps?daddr=Bahnhofplatz+3,+7000+Chur"); + assertGeoPoint(actual, new GeoParsedPoint("Bahnhofplatz 3, 7000 Chur")); + + actual = GeoPointParserUtil.parse( + "https://www.google.com/maps?daddr=Bahnhofplatz+3,+7000+Chur@46.853582,9.529903"); + System.out.println(actual); + assertGeoPoint(actual, new GeoParsedPoint(46.853582, 9.529903)); + } @Test public void testGeoPoint() {