Search in sources :

Example 6 with GeocodingResult

use of net.osmand.binary.GeocodingUtilities.GeocodingResult in project Osmand by osmandapp.

the class GeocodingLookupService method geocode.

private boolean geocode(final LatLon latLon) {
    Location loc = new Location("");
    loc.setLatitude(latLon.getLatitude());
    loc.setLongitude(latLon.getLongitude());
    return app.getLocationProvider().getGeocodingResult(loc, new ResultMatcher<GeocodingResult>() {

        @Override
        public boolean publish(GeocodingResult object) {
            String result = null;
            if (object != null) {
                OsmandSettings settings = app.getSettings();
                String lang = settings.MAP_PREFERRED_LOCALE.get();
                boolean transliterate = settings.MAP_TRANSLITERATE_NAMES.get();
                String geocodingResult = "";
                double relevantDistance = -1;
                if (object.building != null) {
                    String bldName = object.building.getName(lang, transliterate);
                    if (!Algorithms.isEmpty(object.buildingInterpolation)) {
                        bldName = object.buildingInterpolation;
                    }
                    geocodingResult = object.street.getName(lang, transliterate) + " " + bldName + ", " + object.city.getName(lang, transliterate);
                } else if (object.street != null) {
                    geocodingResult = object.street.getName(lang, transliterate) + ", " + object.city.getName(lang, transliterate);
                    relevantDistance = object.getDistanceP();
                } else if (object.city != null) {
                    geocodingResult = object.city.getName(lang, transliterate);
                } else if (object.point != null) {
                    RouteDataObject rd = object.point.getRoad();
                    String sname = rd.getName(lang, transliterate);
                    if (Algorithms.isEmpty(sname)) {
                        sname = "";
                    }
                    String ref = rd.getRef(lang, transliterate, true);
                    if (!Algorithms.isEmpty(ref)) {
                        if (!Algorithms.isEmpty(sname)) {
                            sname += ", ";
                        }
                        sname += ref;
                    }
                    geocodingResult = sname;
                    relevantDistance = object.getDistanceP();
                }
                result = geocodingResult;
                if (relevantDistance == -1) {
                    relevantDistance = object.getDistance();
                }
                if (!Algorithms.isEmpty(result) && relevantDistance > 100) {
                    result = app.getString(R.string.shared_string_near) + " " + result;
                }
            }
            lastFoundAddress = result;
            searchDone = true;
            return true;
        }

        @Override
        public boolean isCancelled() {
            return !hasAnyRequest(latLon);
        }
    });
}
Also used : GeocodingResult(net.osmand.binary.GeocodingUtilities.GeocodingResult) RouteDataObject(net.osmand.binary.RouteDataObject) Location(net.osmand.Location)

Aggregations

GeocodingResult (net.osmand.binary.GeocodingUtilities.GeocodingResult)6 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)4 ArrayList (java.util.ArrayList)3 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)3 GeocodingUtilities (net.osmand.binary.GeocodingUtilities)3 IOException (java.io.IOException)2 List (java.util.List)2 Location (net.osmand.Location)2 RouteDataObject (net.osmand.binary.RouteDataObject)2 Point (java.awt.Point)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 Entity (net.osmand.osm.edit.Entity)1 Node (net.osmand.osm.edit.Node)1 BinaryMapReaderResource (net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource)1 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)1 RoutingConfiguration (net.osmand.router.RoutingConfiguration)1 RoutingContext (net.osmand.router.RoutingContext)1