Search in sources :

Example 1 with SearchPoiTypeFilter

use of net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter in project Osmand by osmandapp.

the class QuickSearchHelper method findAmenity.

public Amenity findAmenity(String name, double lat, double lon, String lang, boolean transliterate) {
    QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
    List<Amenity> amenities = app.getResourceManager().searchAmenities(new SearchPoiTypeFilter() {

        @Override
        public boolean accept(PoiCategory type, String subcategory) {
            return true;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    }, rect.top, rect.left, rect.bottom, rect.right, -1, null);
    MapPoiTypes types = app.getPoiTypes();
    for (Amenity amenity : amenities) {
        String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate);
        if (poiSimpleFormat.equals(name)) {
            return amenity;
        }
    }
    for (Amenity amenity : amenities) {
        String amenityName = amenity.getName(lang, transliterate);
        if (Algorithms.isEmpty(amenityName)) {
            AbstractPoiType st = types.getAnyPoiTypeByKey(amenity.getSubType());
            if (st != null) {
                amenityName = st.getTranslation();
            } else {
                amenityName = amenity.getSubType();
            }
        }
        if (name.contains(amenityName)) {
            return amenity;
        }
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) SearchPoiTypeFilter(net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter) PoiCategory(net.osmand.osm.PoiCategory) AbstractPoiType(net.osmand.osm.AbstractPoiType) QuadRect(net.osmand.data.QuadRect) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Aggregations

SearchPoiTypeFilter (net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter)1 Amenity (net.osmand.data.Amenity)1 QuadRect (net.osmand.data.QuadRect)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 MapPoiTypes (net.osmand.osm.MapPoiTypes)1 PoiCategory (net.osmand.osm.PoiCategory)1