fix of the opportunity to find an address from external sources using google maps links
This commit is contained in:
parent
9e209c2186
commit
2da563815d
1 changed files with 25 additions and 3 deletions
|
@ -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<Void, Void, GeoParsedPoint> {
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue