Class GLSearch


public class GLSearch extends 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).

  • 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 GLMapVectorObject MapObjectNearPoint(@NonNull GLMapViewRenderer mapView, @NonNull 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 GLMapRelation[] RelationsNearPoint(@NonNull GLMapViewRenderer mapView, @NonNull 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 GLMapVectorObject LoadMergedRelationLines(GLMapRelation relation, boolean isForward, @Nullable 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 GLMapVectorObject object)
      Detects category for a vector object.
      Parameters:
      object - Vector object
      Returns:
      Category that matches to object
    • FillSearchCategory

      public static void FillSearchCategory(@NonNull 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<GLMapValue> MatchedCategoryTags(@NonNull 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 GLMapValue GetAddress(@NonNull GLMapVectorObject object, int style, @NonNull 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 GLMapValue[] LocalizedAddressNames(@NonNull GLMapVectorObject object, @NonNull 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 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 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 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 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 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 GLMapVectorObjectList search()
      Performs search synchronously
      Returns:
      result of search
    • merge

      public Object[] merge(@NonNull 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.