The Presentation API includes methods that you can use for geospatial sorting.
The ERecSortKey class is used to specify all sort keys, including geocode sort keys.
To create a geocode sort key, use the four-parameter constructor:
ERecSortKey(String propertyName, boolean isAscending, double latitude, double longitude);
An ERecSortKey
has accessor methods for the latitude and longitude of the reference location:
Note that calling these methods on a non-geocode sort key causes an error.
The type of sort key (GEOCODE_SORT_KEY
or ALPHA_NUM_SORT_KEY
) can be determined using the getType()
method (Java) or the Type
property (.NET).
The code samples below show the use of the accessor methods.
Although you can implement sorting without first retrieving a list of valid sorting keys from the result object, this approach requires that the application have its parameters coordinated properly with the MDEX Engine. The application will have the Ns parameters hard-coded, and will rely on the MDEX Engine to have corresponding parameters. If a navigation request is made with an invalid Ns parameter, that request returns an error from the MDEX Engine.
Example 12. Java example of geocode API methods
ERecSortKey sk = new ERecSortKey("Location", true, 43.0, -73.0); // get sortKeyName == "Location" String sortKeyName = sk.getName(); // get latitude == 43.0 double latitude = sk.getReferenceLatitude(); // get longitude == -73.0 double longitude = sk.getReferenceLongitude(); // get keyType == com.endeca.navigation.ERecSortKey.GEOCODE_SORT_KEY int keyType = sk.getType(); // get sortOrder == com.endeca.navigation.ERecSortKey.ASCENDING int sortOrder = sk.getOrder();
Example 13. .NET example of geocode API methods
ERecSortKey sk = new ERecSortKey("Location", true, 43.0, -73.0); // get sortKeyName == "Location" string sortKeyName = sk.Name; // get latitude == 43.0 double latitude = sk.GetReferenceLatitude(); // get longitude == -73.0 double longitude = sk.GetReferenceLongitude(); // get keyType == Endeca.Navigation.ERecSortKey.GEOCODE_SORT_KEY int keyType = sk.Type; // get sortOrder == com.endeca.navigation.ERecSortKey.ASCENDING int sortOrder = sk.GetOrder();