Package globus.glsearch
Class GLSearch
java.lang.Object
globus.glmap.GLNativeObject
globus.glsearch.GLSearch
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 ClassesModifier and TypeClassDescriptionstatic @interfaceStyle of addressstatic interfaceCallbacks for custom objectsstatic @interfaceMatch typestatic interfaceCallback that provides information for custom objects for search.static @interfacePredefined set of tags -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilter(GLSearchFilter filter) Adds filter to search.voidcancel()Cancels asynchronous search operations started for thisGLSearchinstance.static intCompare to string with collatorstatic longCreates ICU collator with strength set to Primary.static longCreates ICU collator with strength set to Primary and numeric collation is ON.static voidDestroyCollator(long collator) Destroys a collator handle created byCreateCollator()orCreateNumericCollator().static voidDestroyWords(long words) Destroy native object returned by GLSearch#PrepareWords(long, String[]).static voidFillSearchCategory(GLMapVectorObjectList objects) Detects categories for the provided vector objects (in-place).static GLMapValueSplit string into words.static GLMapValueGetAddress(GLMapVectorObject object, int style, GLMapLocaleSettings localeSettings) Formats an address string for the given object.static GLSearchCategoryGetSearchCategory(GLMapVectorObject object) Detects category for a vector object.static voidInitialize(android.content.Context context) Initializes search resources.static GLMapVectorObjectLoadMergedRelationLines(GLMapRelation relation, boolean isForward, GLMapInfo map) Loads all line members from a relation and merges them into a multiline object.static GLMapValue[]LocalizedAddressNames(GLMapVectorObject object, GLMapLocaleSettings localeSettings) Returns all localized address names associated with the object.static GLMapVectorObjectMapObjectNearPoint(GLMapViewRenderer mapView, MapPoint point, double maxDistance) Returns a map object near a point.static android.util.SparseArray<GLMapValue>MatchedCategoryTags(GLMapVectorObject object) Returns tags that define the object's matched category.Object[]merge(GLMapVectorObjectList searchResults, List<Object> customObjects, GLSearch.CustomObjectInfoCallback infoCallback) Merge search results with custom objectsstatic GLMapVectorObjectNearest(double lat, double lon, double maxDist, List<GLSearchFilter> filters) Finds the nearest object to the specified geographic location.static longPrepareWords(long collator, String[] words) Prepares words for collation.static GLMapRelation[]RelationsNearPoint(GLMapViewRenderer mapView, MapPoint point, double maxDistance, GLSearchFilter[] filters) Searches for relations near a point on the map.search()Performs search synchronouslyvoidsearchAsync(GLSearch.ResultsCallback callback) Starts an asynchronous search.voidSets the bounding box where the search will be performed.voidSets center of search.voidsetLimit(int limit) Sets maximum number of results to fetch from mapvoidsetLocaleSettings(GLMapLocaleSettings localeSettings) Sets locale settings that used to sort results by importance.voidsetNeedEnclosingAreas(boolean needEnclosingAreas) Enables loading enclosing areas that are required for address formatting.voidsetObjectTypes(int objectTypes) Set object typesvoidsetTiles(long[] tiles) Adds tile hashes to narrow the search area.static String[]SplitByWords(String string) Splits a string into words using ICU root rules.Methods inherited from class globus.glmap.GLNativeObject
dispose
-
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 fromglobus.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, fromGLMapViewRenderer.convertDisplayToInternal(double, double))maxDistance- maximum distance in screen points (dp)- Returns:
- vector object on map, or
nullif nothing is found withinmaxDistance
-
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 coordinatesmaxDistance- maximum distance in screen points (dp)filters- optional filters for relations- Returns:
- relations near point, or
nullif 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 loadisForward-truefor forward route,falsefor backward routemap- map from where to load relation; ifnull, an arbitrary map will be used- Returns:
- vector object with multiline, or
nullon failure
-
GetSearchCategory
Detects category for a vector object.- Parameters:
object- Vector object- Returns:
- Category that matches to object
-
FillSearchCategory
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
nullif 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 objectstyle- style of addresslocaleSettings- 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 objectlocaleSettings- Locale settings used to find name- Returns:
- array of address names
-
SplitByWords
Splits a string into words using ICU root rules.- Parameters:
string- string to split into words- Returns:
- words from string
-
PrepareWords
Prepares words for collation.- Parameters:
collator- collator that will be used in collationwords- 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 byPrepareWords(long, String[])
-
FindWords
Split string into words. Then checks if all prepared words are equal to start of any word in string- Parameters:
collator- collator to usestring- string where prepared words will be checkedwords- 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 byCreateCollator()orCreateNumericCollator().- Parameters:
collator- native collator object
-
Collate
Compare to string with collator- Parameters:
collator- collator to usea- 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- latitudelon- longitudemaxDist- max search distance in metersfilters- 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
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
Sets the bounding box where the search will be performed.- Parameters:
bbox- Search bounding box in internal map coordinates.
-
setCenter
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
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- iftrue, search will load enclosing areas
-
setObjectTypes
public void setObjectTypes(int objectTypes) Set object types- Parameters:
objectTypes- object types
-
searchAsync
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
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 resultscustomObjects- custom objectsinfoCallback- 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 thisGLSearchinstance.Cancellation is best-effort; already running work may still complete and invoke callbacks.
-