From 940a1c1e0886aa85db4f8b6b2ce38a33510ed8b7 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 5 Sep 2017 13:37:39 +0300 Subject: [PATCH 1/8] Fix #4394 --- .../net/osmand/util/GeoPointParserUtil.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index db33f4e77e..197e8381b6 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -220,6 +220,16 @@ public class GeoPointParserUtil { actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z)); + url = "http://www.openstreetmap.org/search?query=" + qlat + "%2C" + qlon; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(qlat, qlon)); + + url = "http://www.openstreetmap.org/search?query=" + qlat + "%20" + qlon; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(qlat, qlon)); + // http://download.osmand.net/go?lat=34.99393&lon=-106.61568&z=11 url = "http://download.osmand.net/go?lat=" + dlat + "&lon=" + dlon + "&z=" + z; System.out.println("url: " + url); @@ -929,6 +939,22 @@ public class GeoPointParserUtil { lon = parseSilentDouble(vls[2]); } } + Map queryMap = getQueryParameters(uri); + if (queryMap != null) { + String queryStr = queryMap.get("query"); + if (queryStr != null) { + String[] vls = null; + if (queryStr.contains(",")) { + vls = queryStr.split("/|,"); + } else if (queryStr.contains(" ")) { + vls = queryStr.split(" "); + } + if (vls != null && vls.length >= 2) { + lat = parseSilentDouble(vls[0]); + lon = parseSilentDouble(vls[1]); + } + } + } // the query string sometimes has higher resolution values String mlat = getQueryParameter("mlat", uri); if (mlat != null) { From 93d0c3ddbd6e909ab97ebddb4676606800afff26 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 10:28:20 +0300 Subject: [PATCH 2/8] Add support for city search from openstreetmap --- OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 197e8381b6..af70f9ec47 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -569,6 +569,13 @@ public class GeoPointParserUtil { actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(qstr)); + // http://www.openstreetmap.org/search?query=Amsterdam + qstr = "Amsterdam"; + url = "http://www.openstreetmap.org/search?query=" + URLEncoder.encode(qstr); + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(qstr)); + // http://maps.google.com/maps?daddr=760+West+Genesee+Street+Syracuse+NY+13204 qstr = "760 West Genesee Street Syracuse NY 13204"; url = "http://www.google.com/maps?daddr=" + URLEncoder.encode(qstr); @@ -952,6 +959,8 @@ public class GeoPointParserUtil { if (vls != null && vls.length >= 2) { lat = parseSilentDouble(vls[0]); lon = parseSilentDouble(vls[1]); + } else { + return new GeoParsedPoint(URLEncoder.encode(queryStr)); } } } From 0d6ec16222cf7d06ce70bc9eb8f7649092c039e1 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 12:44:10 +0300 Subject: [PATCH 3/8] Add support for openstreetmap general search --- .../net/osmand/util/GeoPointParserUtil.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index af70f9ec47..97d7131d3f 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -576,6 +576,13 @@ public class GeoPointParserUtil { actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(qstr)); + // http://www.openstreetmap.org/search?query=Bloemstraat+51A,+Amsterdam + qstr = "Bloemstraat 51A, Amsterdam"; + url = "http://www.openstreetmap.org/search?query=" + URLEncoder.encode(qstr); + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(qstr)); + // http://maps.google.com/maps?daddr=760+West+Genesee+Street+Syracuse+NY+13204 qstr = "760 West Genesee Street Syracuse NY 13204"; url = "http://www.google.com/maps?daddr=" + URLEncoder.encode(qstr); @@ -935,6 +942,7 @@ public class GeoPointParserUtil { double lat = 0; double lon = 0; int zoom = GeoParsedPoint.NO_ZOOM; + Map queryMap = getQueryParameters(uri); if (fragment != null) { if (fragment.startsWith("map=")) { fragment = fragment.substring("map=".length()); @@ -945,9 +953,7 @@ public class GeoPointParserUtil { lat = parseSilentDouble(vls[1]); lon = parseSilentDouble(vls[2]); } - } - Map queryMap = getQueryParameters(uri); - if (queryMap != null) { + } else if (queryMap != null) { String queryStr = queryMap.get("query"); if (queryStr != null) { String[] vls = null; @@ -959,8 +965,17 @@ public class GeoPointParserUtil { if (vls != null && vls.length >= 2) { lat = parseSilentDouble(vls[0]); lon = parseSilentDouble(vls[1]); + if (lat == 0 || lon == 0) { + if (queryStr.contains("+")) { + queryStr = queryStr.replace("+", " "); + } + return new GeoParsedPoint(queryStr); + } } else { - return new GeoParsedPoint(URLEncoder.encode(queryStr)); + if (queryStr.contains("+")) { + queryStr = queryStr.replace("+", " "); + } + return new GeoParsedPoint(queryStr); } } } From 1313f6d81f56045046de44dbdef348db5262931f Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 13:24:51 +0300 Subject: [PATCH 4/8] Fixes --- .../src/net/osmand/util/GeoPointParserUtil.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 97d7131d3f..65b991ed2d 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -962,20 +962,14 @@ public class GeoPointParserUtil { } else if (queryStr.contains(" ")) { vls = queryStr.split(" "); } - if (vls != null && vls.length >= 2) { + if (vls != null && vls.length == 2) { lat = parseSilentDouble(vls[0]); lon = parseSilentDouble(vls[1]); if (lat == 0 || lon == 0) { - if (queryStr.contains("+")) { - queryStr = queryStr.replace("+", " "); - } - return new GeoParsedPoint(queryStr); + return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); } } else { - if (queryStr.contains("+")) { - queryStr = queryStr.replace("+", " "); - } - return new GeoParsedPoint(queryStr); + return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); } } } From 8514e8a2ce77240238679c060f61f40a3f74f938 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 7 Sep 2017 12:44:40 +0200 Subject: [PATCH 5/8] Update GeoPointParserUtil.java --- .../src/net/osmand/util/GeoPointParserUtil.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 65b991ed2d..3ba017c126 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -956,20 +956,14 @@ public class GeoPointParserUtil { } else if (queryMap != null) { String queryStr = queryMap.get("query"); if (queryStr != null) { - String[] vls = null; - if (queryStr.contains(",")) { - vls = queryStr.split("/|,"); - } else if (queryStr.contains(" ")) { - vls = queryStr.split(" "); - } + queryStr = queryStr.replace("+", " ").replace("/|,", " "); + String[] vls = queryStr.split(" "); if (vls != null && vls.length == 2) { lat = parseSilentDouble(vls[0]); lon = parseSilentDouble(vls[1]); - if (lat == 0 || lon == 0) { - return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); - } - } else { - return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); + } + if (lat == 0 || lon == 0) { + return new GeoParsedPoint(queryStr); } } } From 53992a2585651b7ec4cd34acdeb5250e8c4642a8 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 18:38:31 +0300 Subject: [PATCH 6/8] Fix parsing --- .../src/net/osmand/util/GeoPointParserUtil.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 3ba017c126..65b991ed2d 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -956,14 +956,20 @@ public class GeoPointParserUtil { } else if (queryMap != null) { String queryStr = queryMap.get("query"); if (queryStr != null) { - queryStr = queryStr.replace("+", " ").replace("/|,", " "); - String[] vls = queryStr.split(" "); + String[] vls = null; + if (queryStr.contains(",")) { + vls = queryStr.split("/|,"); + } else if (queryStr.contains(" ")) { + vls = queryStr.split(" "); + } if (vls != null && vls.length == 2) { lat = parseSilentDouble(vls[0]); lon = parseSilentDouble(vls[1]); - } - if (lat == 0 || lon == 0) { - return new GeoParsedPoint(queryStr); + if (lat == 0 || lon == 0) { + return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); + } + } else { + return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); } } } From 8f1ba86a14069b3a9597ec4dade9928f14634f07 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 12:27:53 +0300 Subject: [PATCH 7/8] Fix --- .../src/net/osmand/util/GeoPointParserUtil.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 65b991ed2d..1ea3a764f1 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -581,7 +581,7 @@ public class GeoPointParserUtil { url = "http://www.openstreetmap.org/search?query=" + URLEncoder.encode(qstr); System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); - assertGeoPoint(actual, new GeoParsedPoint(qstr)); + assertGeoPoint(actual, new GeoParsedPoint(qstr.replace(',',' '))); // http://maps.google.com/maps?daddr=760+West+Genesee+Street+Syracuse+NY+13204 qstr = "760 West Genesee Street Syracuse NY 13204"; @@ -956,20 +956,16 @@ public class GeoPointParserUtil { } else if (queryMap != null) { String queryStr = queryMap.get("query"); if (queryStr != null) { - String[] vls = null; - if (queryStr.contains(",")) { - vls = queryStr.split("/|,"); - } else if (queryStr.contains(" ")) { - vls = queryStr.split(" "); - } - if (vls != null && vls.length == 2) { + queryStr = queryStr.replace("+", " ").replace(",", " "); + String[] vls = queryStr.split(" "); + if (vls.length == 2) { lat = parseSilentDouble(vls[0]); lon = parseSilentDouble(vls[1]); if (lat == 0 || lon == 0) { - return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); + return new GeoParsedPoint(queryStr); } } else { - return new GeoParsedPoint(queryStr.replace("+", " ").replace("/|,", " ")); + return new GeoParsedPoint(queryStr); } } } From bec2fac47ae50e02c8469a577764dbcdf132d36b Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 12:31:09 +0300 Subject: [PATCH 8/8] Remove copy paste --- OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 1ea3a764f1..3f0cc32f9d 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -961,10 +961,8 @@ public class GeoPointParserUtil { if (vls.length == 2) { lat = parseSilentDouble(vls[0]); lon = parseSilentDouble(vls[1]); - if (lat == 0 || lon == 0) { - return new GeoParsedPoint(queryStr); - } - } else { + } + if (lat == 0 || lon == 0) { return new GeoParsedPoint(queryStr); } }