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;
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.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader;
@ -14,18 +21,12 @@ import net.osmand.router.RoutingConfiguration;
import net.osmand.router.RoutingContext;
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 {
private RouteDataObject lastFound;
private Location lastAskedLocation = null;
private RoutingContext ctx;
private RoutingContext defCtx;
private OsmandApplication app;
private ApplicationMode am;
@ -48,6 +49,9 @@ public class CurrentPositionHelper {
RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10,
new HashMap<String, String>());
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
public void run() {
try {
final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude());
final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude(),
geoCoding != null);
if (storeFound) {
lastAskedLocation = loc;
lastFound = gr.isEmpty() ? null : gr.get(0).point.getRoad();
@ -116,6 +121,9 @@ public class CurrentPositionHelper {
}
}
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();
app.runInUIThread(new Runnable() {
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()) {
initCtx(app);
if (ctx == 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) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, R.string.no_location_permission, Toast.LENGTH_LONG).show();
return false;
}
return true;

View file

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