Sets an anchor point for geosphere distance calculations.
Namespace: Gronewold.SphinxConnectorAssembly: Gronewold.SphinxConnector (in Gronewold.SphinxConnector.dll) Version: 2.7.0.3011 (2.7.0.3011)
Syntax
| C# |
|---|
public void SetGeoAnchor( string latitudeAttribute, string longitudeAttribute, float latitude, float longitude ) |
| Visual Basic |
|---|
Public Sub SetGeoAnchor ( _ latitudeAttribute As String, _ longitudeAttribute As String, _ latitude As Single, _ longitude As Single _ ) |
Parameters
- latitudeAttribute
- Type: System..::..String
The name of the lattitude attribute in the index.
- longitudeAttribute
- Type: System..::..String
The name of the longitude attribute in the index.
- latitude
- Type: System..::..Single
The latitude of the anchor point in radians.
- longitude
- Type: System..::..Single
The longitude of the anchor point in radians.
Remarks
Sphinx expects latitude and longitude to be in radians (the attributes in the index and the parameters to SetGeoAnchor).
The SphinxHelper class contains methods to convert from degrees to radians and vice versa.
The unit of @geodist is meters.
Examples
The following example shows how to filter search results based on a geo distance calculation.
CopyC#
float latitude = 0.678892874f; float longitue = -1.34454090f; SphinxClient sphinxClient = new SphinxClient(); sphinxClient.SearchOptions.SetGeoAnchor("latitude", "longitude", latitude, longitude); //Return all results within 20 km of the anchor point sphinxClient.SearchOptions.SetFilterRange<SphinxFloat>("@geodist", 0, 20000);