GLSearch

Objective-C


@interface GLSearch : NSObject

Swift

class GLSearch : NSObject

GLSearch class performs search in offline maps.

  • Initialize GLSearch from a JSON string.

    Declaration

    Objective-C

    - (instancetype _Nullable)initFromJSON:(nonnull NSString *)json;

    Swift

    init?(fromJSON json: String)

    Parameters

    json

    JSON string with parameters.

  • Adds a set of tile hashes to use for search (child tiles will be skipped).

    Declaration

    Objective-C

    - (void)setTiles:(nonnull NSSet<NSNumber *> *)tiles;

    Swift

    func setTiles(_ tiles: Set<NSNumber>)

    Parameters

    tiles

    Set of tile hashes.

  • Sets locale settings that are used to sort results by importance. Results in the user’s language are displayed on top.

    Declaration

    Objective-C

    - (void)setLocaleSettings:(nonnull GLMapLocaleSettings *)localeSettings;

    Swift

    func setLocaleSettings(_ localeSettings: GLMapLocaleSettings)

    Parameters

    localeSettings

    Language priority settings.

  • Adds a filter to the search. The result of the search will contain objects that match all filters.

    Declaration

    Objective-C

    - (void)addFilter:(nonnull GLSearchFilter *)filter;

    Swift

    func add(_ filter: GLSearchFilter)

    Parameters

    filter

    Filter to add.

  • Sets the maximum number of results to fetch from the map.

    Declaration

    Objective-C

    @property (nonatomic) NSUInteger limit;

    Swift

    var limit: UInt { get set }
  • Sets the center of the search. The distance from this center will define the importance of the object. Usually, the center is the user’s location or the center of the screen.

    Declaration

    Objective-C

    @property (nonatomic) GLMapPoint center;

    Swift

    var center: GLMapPoint { get set }
  • Sets the bounding box where the search will be performed.

    Declaration

    Objective-C

    @property (nonatomic) GLMapBBox bbox;

    Swift

    var bbox: GLMapBBox { get set }
  • Set this value to YES if you plan to get the address of objects. Loading address after search is much faster (cache reuse, bulk loading).

    Declaration

    Objective-C

    @property (nonatomic) BOOL needEnclosingAreas;

    Swift

    var needEnclosingAreas: Bool { get set }
  • Types of objects

    Declaration

    Objective-C

    @property (nonatomic) GLMapVectorObjectType objectTypes;

    Swift

    var objectTypes: GLMapVectorObjectType { get set }
  • Performs the search synchronously.

    Declaration

    Objective-C

    - (nonnull GLMapVectorObjectArray *)search;

    Swift

    func search() -> GLMapVectorObjectArray
  • Starts the search.

    Declaration

    Objective-C

    - (void)searchAsyncWithCompletionBlock:
        (nonnull GLSearchCompletionBlock)completionBlock;

    Swift

    func searchAsync() async -> GLMapVectorObjectArray

    Parameters

    completionBlock

    Block will be called when the search is finished.

  • Merges search results with custom objects.

    Declaration

    Objective-C

    - (nonnull NSArray *)mergeSearchResults:
                             (nonnull GLMapVectorObjectArray *)searchResults
                          withCustomObjects:(nonnull NSArray *)customObjects
                                      using:(nonnull GLSearchInfoBlock)infoBlock;

    Swift

    func mergeResults(_ searchResults: GLMapVectorObjectArray, withCustomObjects customObjects: [Any], using infoBlock: @escaping GLSearchInfoBlock) -> [Any]

    Parameters

    searchResults

    Search results array.

    customObjects

    Array of custom objects.

    infoBlock

    Block that returns location, category, and extra score for the custom object.

    Return Value

    Returns a sorted array.

  • Cancels the search operation.

    Declaration

    Objective-C

    - (void)cancel;

    Swift

    func cancel()
  • Serialize all settings as a JSON string.

    Declaration

    Objective-C

    - (nonnull NSString *)toJSON;

    Swift

    func toJSON() -> String

    Return Value

    Returns a JSON string with search settings.

  • Splits a string into words with rules that were used to generate search indexes. Uses ICU inside. Works even for Japanese glyphs without spaces.

    Declaration

    Objective-C

    + (nonnull NSArray<NSString *> *)splitByWords:(nonnull NSString *)string;

    Swift

    class func split(byWords string: String) -> [String]

    Parameters

    string

    String with long text.

    Return Value

    Returns an array of words.

  • Finds the nearest vector object to a certain location on the map.

    Declaration

    Objective-C

    + (GLMapVectorObject *_Nullable)
        nearestToPoint:(GLMapPoint)point
           maxDistance:(double)distance
           withFilters:(NSArray<GLSearchFilter *> *_Nullable)filters;

    Swift

    class func nearest(to point: GLMapPoint, maxDistance distance: Double, with filters: [GLSearchFilter]?) -> GLMapVectorObject?

    Parameters

    point

    Point.

    distance

    Maximum distance from the point.

    filters

    Search filters applied to results.

    Return Value

    Returns a vector object or nil if nothing was found in the distance radius.

  • Finds a relation with a near point with a given osmID.

    Declaration

    Objective-C

    + (GLMapRelation *_Nullable)findRelationNearPoint:(GLMapPoint)point
                                                osmID:(int64_t)osmID;

    Swift

    class func findRelationNearPoint(_ point: GLMapPoint, osmID: Int64) -> GLMapRelation?

    Parameters

    point

    Point.

    osmID

    OSM ID.