From 2da563815d554248c34e5c5b82f5f189fd4254f3 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 30 Dec 2020 13:31:41 +0200 Subject: [PATCH 1/3] fix of the opportunity to find an address from external sources using google maps links --- .../activities/search/GeoIntentActivity.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 1e8ff552b4..951ba74b16 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -1,9 +1,12 @@ package net.osmand.plus.activities.search; import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.Intent; +import android.location.Address; +import android.location.Geocoder; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -26,6 +29,9 @@ import net.osmand.util.Algorithms; import net.osmand.util.GeoPointParserUtil; import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; +import java.io.IOException; +import java.util.Locale; + public class GeoIntentActivity extends OsmandListActivity { private ProgressDialog progressDlg; @@ -53,7 +59,7 @@ public class GeoIntentActivity extends OsmandListActivity { if (intent != null) { final ProgressDialog progress = ProgressDialog.show(GeoIntentActivity.this, getString(R.string.searching), getString(R.string.searching_address)); - final GeoIntentTask task = new GeoIntentTask(progress, intent); + final GeoIntentTask task = new GeoIntentTask(progress, intent, this); progress.setOnCancelListener(new OnCancelListener() { @Override @@ -84,10 +90,12 @@ public class GeoIntentActivity extends OsmandListActivity { private class GeoIntentTask extends AsyncTask { private final ProgressDialog progress; private final Intent intent; + private Context context; - private GeoIntentTask(final ProgressDialog progress, final Intent intent) { + private GeoIntentTask(final ProgressDialog progress, final Intent intent, Context context) { this.progress = progress; this.intent = intent; + this.context = context; } @Override @@ -113,7 +121,21 @@ public class GeoIntentActivity extends OsmandListActivity { Thread.sleep(200); } Uri uri = intent.getData(); - return GeoPointParserUtil.parse(uri.toString()); + GeoParsedPoint gpp; + Address address = null; + try { + address = new Geocoder(context, Locale.getDefault()) + .getFromLocationName(uri.toString(), 1) + .get(0); + } catch (IndexOutOfBoundsException | IOException e) { + e.printStackTrace(); + } + if (address != null) { + gpp = new GeoParsedPoint(address.getLatitude(), address.getLongitude(), GeoParsedPoint.NO_ZOOM); + } else { + gpp = GeoPointParserUtil.parse(uri.toString()); + } + return gpp; } catch (Exception e) { return null; } From 0205628a486fabb96b2dae5d637909d8292fcb2f Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 31 Dec 2020 15:15:17 +0200 Subject: [PATCH 2/3] rolled back previous changes; fix address uri without lat & lon in searchRequest (example: geo:0,0?q=Van+Bleiswijkstraat+66,+2582+LG+The+Hague) --- .../net/osmand/util/GeoPointParserUtil.java | 4 +++ .../activities/search/GeoIntentActivity.java | 28 ++----------------- 2 files changed, 7 insertions(+), 25 deletions(-) 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 951ae870e2..f46f4f6f70 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -558,6 +558,10 @@ public class GeoPointParserUtil { if (lat == 0.0 && lon == 0.0 && positionInSearchRequestMatcher.find()) { lat = Double.valueOf(positionInSearchRequestMatcher.group(1)); lon = Double.valueOf(positionInSearchRequestMatcher.group(2)); + if (lat < -90 || lat > 90 || lon < -180 || lon > 180) { + lat = 0.0; + lon = 0.0; + } } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 951ba74b16..1e8ff552b4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -1,12 +1,9 @@ package net.osmand.plus.activities.search; import android.app.ProgressDialog; -import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.Intent; -import android.location.Address; -import android.location.Geocoder; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -29,9 +26,6 @@ import net.osmand.util.Algorithms; import net.osmand.util.GeoPointParserUtil; import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; -import java.io.IOException; -import java.util.Locale; - public class GeoIntentActivity extends OsmandListActivity { private ProgressDialog progressDlg; @@ -59,7 +53,7 @@ public class GeoIntentActivity extends OsmandListActivity { if (intent != null) { final ProgressDialog progress = ProgressDialog.show(GeoIntentActivity.this, getString(R.string.searching), getString(R.string.searching_address)); - final GeoIntentTask task = new GeoIntentTask(progress, intent, this); + final GeoIntentTask task = new GeoIntentTask(progress, intent); progress.setOnCancelListener(new OnCancelListener() { @Override @@ -90,12 +84,10 @@ public class GeoIntentActivity extends OsmandListActivity { private class GeoIntentTask extends AsyncTask { private final ProgressDialog progress; private final Intent intent; - private Context context; - private GeoIntentTask(final ProgressDialog progress, final Intent intent, Context context) { + private GeoIntentTask(final ProgressDialog progress, final Intent intent) { this.progress = progress; this.intent = intent; - this.context = context; } @Override @@ -121,21 +113,7 @@ public class GeoIntentActivity extends OsmandListActivity { Thread.sleep(200); } Uri uri = intent.getData(); - GeoParsedPoint gpp; - Address address = null; - try { - address = new Geocoder(context, Locale.getDefault()) - .getFromLocationName(uri.toString(), 1) - .get(0); - } catch (IndexOutOfBoundsException | IOException e) { - e.printStackTrace(); - } - if (address != null) { - gpp = new GeoParsedPoint(address.getLatitude(), address.getLongitude(), GeoParsedPoint.NO_ZOOM); - } else { - gpp = GeoPointParserUtil.parse(uri.toString()); - } - return gpp; + return GeoPointParserUtil.parse(uri.toString()); } catch (Exception e) { return null; } From 3566ec765254ceaa1150463ab12fa8463fb4aa1b Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 8 Jan 2021 19:05:02 +0200 Subject: [PATCH 3/3] fix previous changes; add new check; --- .../java/net/osmand/util/GeoPointParserUtil.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 f46f4f6f70..3906aff004 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -553,14 +553,19 @@ public class GeoPointParserUtil { } if (searchRequest != null) { + String searchPattern = Pattern.compile("(?:\\.|,|\\s+|\\+|[+-]?\\d+(?:\\.\\d+)?)").pattern(); + String[] search = searchRequest.split(searchPattern); + if (search.length > 0) { + return new GeoParsedPoint(searchRequest); + } final Matcher positionInSearchRequestMatcher = positionPattern.matcher(searchRequest); if (lat == 0.0 && lon == 0.0 && positionInSearchRequestMatcher.find()) { - lat = Double.valueOf(positionInSearchRequestMatcher.group(1)); - lon = Double.valueOf(positionInSearchRequestMatcher.group(2)); - if (lat < -90 || lat > 90 || lon < -180 || lon > 180) { - lat = 0.0; - lon = 0.0; + double tempLat = Double.valueOf(positionInSearchRequestMatcher.group(1)); + double tempLon = Double.valueOf(positionInSearchRequestMatcher.group(2)); + if (tempLat >= -90 && tempLat <= 90 && tempLon >= -180 && tempLon <= 180) { + lat = tempLat; + lon = tempLon; } } }