Update geocoding

This commit is contained in:
Victor Shcherb 2015-12-17 17:59:39 +02:00
parent 6277a4de4a
commit b06d004f77
3 changed files with 19 additions and 12 deletions

View file

@ -1,5 +1,12 @@
package net.osmand.plus; package net.osmand.plus;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
@ -14,18 +21,12 @@ import net.osmand.router.RoutingConfiguration;
import net.osmand.router.RoutingContext; import net.osmand.router.RoutingContext;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class CurrentPositionHelper { public class CurrentPositionHelper {
private RouteDataObject lastFound; private RouteDataObject lastFound;
private Location lastAskedLocation = null; private Location lastAskedLocation = null;
private RoutingContext ctx; private RoutingContext ctx;
private RoutingContext defCtx;
private OsmandApplication app; private OsmandApplication app;
private ApplicationMode am; private ApplicationMode am;
@ -48,6 +49,9 @@ public class CurrentPositionHelper {
RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10, RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10,
new HashMap<String, String>()); new HashMap<String, String>());
ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles()); ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles());
RoutingConfiguration defCfg = app.getDefaultRoutingConfig().build(GeneralRouterProfile.CAR.name().toLowerCase(), 10,
new HashMap<String, String>());
defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, app.getResourceManager().getRoutingMapFiles());
} }
@ -59,7 +63,8 @@ public class CurrentPositionHelper {
@Override @Override
public void run() { public void run() {
try { try {
final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude()); final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude(),
geoCoding != null);
if (storeFound) { if (storeFound) {
lastAskedLocation = loc; lastAskedLocation = loc;
lastFound = gr.isEmpty() ? null : gr.get(0).point.getRoad(); lastFound = gr.isEmpty() ? null : gr.get(0).point.getRoad();
@ -116,6 +121,9 @@ public class CurrentPositionHelper {
} }
} }
Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR); Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
// for(GeocodingResult rt : complete) {
// System.out.println(rt.toString());
// }
final GeocodingResult rts = complete.size() > 0 ? complete.get(0) : new GeocodingResult(); final GeocodingResult rts = complete.size() > 0 ? complete.get(0) : new GeocodingResult();
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
public void run() { public void run() {
@ -175,13 +183,13 @@ public class CurrentPositionHelper {
} }
private synchronized List<GeocodingResult> runUpdateInThread(double lat, double lon) throws IOException { private synchronized List<GeocodingResult> runUpdateInThread(double lat, double lon, boolean geocoding) throws IOException {
if (ctx == null || am != app.getSettings().getApplicationMode()) { if (ctx == null || am != app.getSettings().getApplicationMode()) {
initCtx(app); initCtx(app);
if (ctx == null) { if (ctx == null) {
return null; return null;
} }
} }
return new GeocodingUtilities().reverseGeocodingSearch(ctx, lat, lon); return new GeocodingUtilities().reverseGeocodingSearch(geocoding ? defCtx : ctx, lat, lon);
} }
} }

View file

@ -929,7 +929,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
public static boolean isLocationPermissionAvailable(Context context) { public static boolean isLocationPermissionAvailable(Context context) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, R.string.no_location_permission, Toast.LENGTH_LONG).show();
return false; return false;
} }
return true; return true;

View file

@ -328,7 +328,7 @@ public class MapControlsLayer extends OsmandMapLayer {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
} else { } else {
ActivityCompat.requestPermissions(mapActivity, ActivityCompat.requestPermissions(mapActivity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION);
} }
} }