Class GLSearch

java.lang.Object
globus.glmap.GLNativeObject
globus.glsearch.GLSearch

public class GLSearch extends globus.glmap.GLNativeObject
Offline search APIs for objects stored in downloaded maps.

GLSearch can be used as a static utility (for example, "near point" queries) or as a configurable search rule that you build and execute via search() / searchAsync(ResultsCallback).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Style of address
    static interface 
    Callbacks for custom objects
    static @interface 
    Match type
    static interface 
    Callback that provides information for custom objects for search.
    static @interface 
    Predefined set of tags
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds filter to search.
    void
    Cancels asynchronous search operations started for this GLSearch instance.
    static int
    Collate(long collator, String a, String b)
    Compare to string with collator
    static long
    Creates ICU collator with strength set to Primary.
    static long
    Creates ICU collator with strength set to Primary and numeric collation is ON.
    static void
    DestroyCollator(long collator)
    Destroys a collator handle created by CreateCollator() or CreateNumericCollator().
    static void
    DestroyWords(long words)
    Destroy native object returned by GLSearch#PrepareWords(long, String[]).
    static void
    FillSearchCategory(globus.glmap.GLMapVectorObjectList objects)
    Detects categories for the provided vector objects (in-place).
    static globus.glmap.GLMapValue
    FindWords(long collator, String string, long words)
    Split string into words.
    static globus.glmap.GLMapValue
    GetAddress(globus.glmap.GLMapVectorObject object, int style, globus.glmap.GLMapLocaleSettings localeSettings)
    Formats an address string for the given object.
    GetSearchCategory(globus.glmap.GLMapVectorObject object)
    Detects category for a vector object.
    static void
    Initialize(android.content.Context context)
    Initializes search resources.
    static globus.glmap.GLMapVectorObject
    LoadMergedRelationLines(globus.glmap.GLMapRelation relation, boolean isForward, globus.glmap.GLMapInfo map)
    Loads all line members from a relation and merges them into a multiline object.
    static globus.glmap.GLMapValue[]
    LocalizedAddressNames(globus.glmap.GLMapVectorObject object, globus.glmap.GLMapLocaleSettings localeSettings)
    Returns all localized address names associated with the object.
    static globus.glmap.GLMapVectorObject
    MapObjectNearPoint(globus.glmap.GLMapViewRenderer mapView, globus.glmap.MapPoint point, double maxDistance)
    Returns a map object near a point.
    static android.util.SparseArray<globus.glmap.GLMapValue>
    MatchedCategoryTags(globus.glmap.GLMapVectorObject object)
    Returns tags that define the object's matched category.
    merge(globus.glmap.GLMapVectorObjectList searchResults, List<Object> customObjects, GLSearch.CustomObjectInfoCallback infoCallback)
    Merge search results with custom objects
    static globus.glmap.GLMapVectorObject
    Nearest(double lat, double lon, double maxDist, List<GLSearchFilter> filters)
    Finds the nearest object to the specified geographic location.
    static long
    PrepareWords(long collator, String[] words)
    Prepares words for collation.
    static globus.glmap.GLMapRelation[]
    RelationsNearPoint(globus.glmap.GLMapViewRenderer mapView, globus.glmap.MapPoint point, double maxDistance, GLSearchFilter[] filters)
    Searches for relations near a point on the map.
    globus.glmap.GLMapVectorObjectList
    Performs search synchronously
    void
    Starts an asynchronous search.
    void
    setBBox(globus.glmap.GLMapBBox bbox)
    Sets the bounding box where the search will be performed.
    void
    setCenter(globus.glmap.MapPoint center)
    Sets center of search.
    void
    setLimit(int limit)
    Sets maximum number of results to fetch from map
    void
    setLocaleSettings(globus.glmap.GLMapLocaleSettings localeSettings)
    Sets locale settings that used to sort results by importance.
    void
    setNeedEnclosingAreas(boolean needEnclosingAreas)
    Enables loading enclosing areas that are required for address formatting.
    void
    setObjectTypes(int objectTypes)
    Set object types
    void
    setTiles(long[] tiles)
    Adds tile hashes to narrow the search area.
    static String[]
    Splits a string into words using ICU root rules.

    Methods inherited from class globus.glmap.GLNativeObject

    dispose

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GLSearch

      public GLSearch()
      Default constructor
  • Method Details

    • Initialize

      public static void Initialize(@NonNull android.content.Context context)
      Initializes search resources.

      Call this method once (typically in Application.onCreate()) before using other APIs from globus.glsearch.

      Parameters:
      context - context used to load ICU and categories data from assets
    • MapObjectNearPoint

      public static globus.glmap.GLMapVectorObject MapObjectNearPoint(@NonNull globus.glmap.GLMapViewRenderer mapView, @NonNull globus.glmap.MapPoint point, double maxDistance)
      Returns a map object near a point.
      Parameters:
      mapView - renderer where map is displayed (must be attached to a surface to compute screen distances)
      point - reference point in internal map coordinates (for example, from GLMapViewRenderer.convertDisplayToInternal(double, double))
      maxDistance - maximum distance in screen points (dp)
      Returns:
      vector object on map, or null if nothing is found within maxDistance
    • RelationsNearPoint

      public static globus.glmap.GLMapRelation[] RelationsNearPoint(@NonNull globus.glmap.GLMapViewRenderer mapView, @NonNull globus.glmap.MapPoint point, double maxDistance, @Nullable GLSearchFilter[] filters)
      Searches for relations near a point on the map.
      Parameters:
      mapView - renderer where map is displayed (must be attached to a surface to compute screen distances)
      point - reference point in internal map coordinates
      maxDistance - maximum distance in screen points (dp)
      filters - optional filters for relations
      Returns:
      relations near point, or null if none found
    • LoadMergedRelationLines

      @Nullable public static globus.glmap.GLMapVectorObject LoadMergedRelationLines(globus.glmap.GLMapRelation relation, boolean isForward, @Nullable globus.glmap.GLMapInfo map)
      Loads all line members from a relation and merges them into a multiline object.
      Parameters:
      relation - relation to load
      isForward - true for forward route, false for backward route
      map - map from where to load relation; if null, an arbitrary map will be used
      Returns:
      vector object with multiline, or null on failure
    • GetSearchCategory

      @Nullable public static GLSearchCategory GetSearchCategory(@NonNull globus.glmap.GLMapVectorObject object)
      Detects category for a vector object.
      Parameters:
      object - Vector object
      Returns:
      Category that matches to object
    • FillSearchCategory

      public static void FillSearchCategory(@NonNull globus.glmap.GLMapVectorObjectList objects)
      Detects categories for the provided vector objects (in-place).
      Parameters:
      objects - vector objects to enrich with category information
    • MatchedCategoryTags

      @Nullable public static android.util.SparseArray<globus.glmap.GLMapValue> MatchedCategoryTags(@NonNull globus.glmap.GLMapVectorObject object)
      Returns tags that define the object's matched category.
      Parameters:
      object - vector object
      Returns:
      mapping from tag hash to tag value, or null if no category matches
    • GetAddress

      @Nullable public static globus.glmap.GLMapValue GetAddress(@NonNull globus.glmap.GLMapVectorObject object, int style, @NonNull globus.glmap.GLMapLocaleSettings localeSettings)
      Formats an address string for the given object.
      Parameters:
      object - vector object
      style - style of address
      localeSettings - locale settings
      Returns:
      address formatted with given style
    • LocalizedAddressNames

      @Nullable public static globus.glmap.GLMapValue[] LocalizedAddressNames(@NonNull globus.glmap.GLMapVectorObject object, @NonNull globus.glmap.GLMapLocaleSettings localeSettings)
      Returns all localized address names associated with the object.
      Parameters:
      object - vector object
      localeSettings - Locale settings used to find name
      Returns:
      array of address names
    • SplitByWords

      @NonNull public static String[] SplitByWords(@NonNull String string)
      Splits a string into words using ICU root rules.
      Parameters:
      string - string to split into words
      Returns:
      words from string
    • PrepareWords

      public static long PrepareWords(long collator, @NonNull String[] words)
      Prepares words for collation.
      Parameters:
      collator - collator that will be used in collation
      words - words to prepare
      Returns:
      opaque native handle; must be destroyed via DestroyWords(long) when not needed
    • DestroyWords

      public static void DestroyWords(long words)
      Destroy native object returned by GLSearch#PrepareWords(long, String[]).
      Parameters:
      words - native handle returned by PrepareWords(long, String[])
    • FindWords

      @Nullable public static globus.glmap.GLMapValue FindWords(long collator, @NonNull String string, long words)
      Split string into words. Then checks if all prepared words are equal to start of any word in string
      Parameters:
      collator - collator to use
      string - string where prepared words will be checked
      words - prepared words
      Returns:
      value that contains same string, but with highlight information. Null if not all prepared words are in string
    • CreateCollator

      public static long CreateCollator()
      Creates ICU collator with strength set to Primary. For example "Straße" equal to "sTrassE" with this collator
      Returns:
      opaque native handle; must be destroyed via DestroyCollator(long) when not needed
    • CreateNumericCollator

      public static long CreateNumericCollator()
      Creates ICU collator with strength set to Primary and numeric collation is ON. For example "Straße 10" greater "sTrassE 2" with this collator
      Returns:
      opaque native handle; must be destroyed via DestroyCollator(long) when not needed
    • DestroyCollator

      public static void DestroyCollator(long collator)
      Destroys a collator handle created by CreateCollator() or CreateNumericCollator().
      Parameters:
      collator - native collator object
    • Collate

      public static int Collate(long collator, @Nullable String a, @Nullable String b)
      Compare to string with collator
      Parameters:
      collator - collator to use
      a - the first object to be compared.
      b - the second object to be compared.
      Returns:
      a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
    • Nearest

      @Nullable public static globus.glmap.GLMapVectorObject Nearest(double lat, double lon, double maxDist, @Nullable List<GLSearchFilter> filters)
      Finds the nearest object to the specified geographic location.
      Parameters:
      lat - latitude
      lon - longitude
      maxDist - max search distance in meters
      filters - search filters
      Returns:
      nearest object or null
    • setTiles

      public void setTiles(@NonNull long[] tiles)
      Adds tile hashes to narrow the search area. Child tiles will be skipped.
      Parameters:
      tiles - array of tile hashes
    • setLocaleSettings

      public void setLocaleSettings(@NonNull globus.glmap.GLMapLocaleSettings localeSettings)
      Sets locale settings that used to sort results by importance. Results in user language displayed on top.
      Parameters:
      localeSettings - Language priority settings.
    • setLimit

      public void setLimit(int limit)
      Sets maximum number of results to fetch from map
      Parameters:
      limit - Results limit
    • setBBox

      public void setBBox(@NonNull globus.glmap.GLMapBBox bbox)
      Sets the bounding box where the search will be performed.
      Parameters:
      bbox - Search bounding box in internal map coordinates.
    • setCenter

      public void setCenter(@NonNull globus.glmap.MapPoint center)
      Sets center of search. Distance from this center will define importance of object. Usually center is user location or center of the screen.
      Parameters:
      center - Center point in internal map coordinates.
    • addFilter

      public void addFilter(@NonNull GLSearchFilter filter)
      Adds filter to search. Result of search will contain objects that matches all filters
      Parameters:
      filter - filter to add.
    • setNeedEnclosingAreas

      public void setNeedEnclosingAreas(boolean needEnclosingAreas)
      Enables loading enclosing areas that are required for address formatting.

      If you plan to call GetAddress(GLMapVectorObject, int, GLMapLocaleSettings) for the results, enabling this can make address formatting faster by preloading enclosing areas. It may increase search time and memory usage.

      Parameters:
      needEnclosingAreas - if true, search will load enclosing areas
    • setObjectTypes

      public void setObjectTypes(int objectTypes)
      Set object types
      Parameters:
      objectTypes - object types
    • searchAsync

      public void searchAsync(@NonNull GLSearch.ResultsCallback callback)
      Starts an asynchronous search.

      The callback is invoked on a background thread. If you update UI, post back to the main thread.

      Parameters:
      callback - callback invoked when search is finished
    • search

      @NonNull public globus.glmap.GLMapVectorObjectList search()
      Performs search synchronously
      Returns:
      result of search
    • merge

      public Object[] merge(@NonNull globus.glmap.GLMapVectorObjectList searchResults, @NonNull List<Object> customObjects, @NonNull GLSearch.CustomObjectInfoCallback infoCallback)
      Merge search results with custom objects
      Parameters:
      searchResults - search results
      customObjects - custom objects
      infoCallback - callback that will provide information about object
      Returns:
      merged array, sorted by the same ranking rules as regular search results
    • cancel

      public void cancel()
      Cancels asynchronous search operations started for this GLSearch instance.

      Cancellation is best-effort; already running work may still complete and invoke callbacks.