Skip to main content

Sorting by Location Information

When setting items on a map, you can use the order_query to sort the contents based on the distance from a specified location by specifying the sort order and latitude/longitude.
Furthermore, distance information (in kilometers) from the specified location will be added to the response under the item name ext_X_distance.

Configuration

Sorting with order_query

Specify the sort order and latitude/longitude in the format of identifier=order=latitude:longitude, and specify it in the endpoint parameter.
Please URL encode the parameter.

Request Example

  • order_query=ext_1=DESC=3.1065323937409204:101.58251235994912

Request URL
https://sitekey.g.kuroco.app/rcms-api/1/map_test?order_query=ext_1%3DDESC%3D3.1065323937409204%3A101.58251235994912

OrderDescription
DESCSort in descending order from the specified latitude/longitude.
ASCSort in ascending order from the specified latitude/longitude.
NoneThe distance from the specified latitude and longitude will be included in the additional response, but the order will not be changed.
Specify using identifier==latitude:longitude.

Response Example

{
"list": [
{
"subject": "Tokyo",
"ext_1_distance": "5337.28",
"ext_1": {
"gmap_x": "139.7671248",
"gmap_y": "35.68123620000001",
"gmap_type": "roadmap",
"gmap_zoom": "14",
"gmap_place_id": "ChIJC3Cf2PuLGGAROO00ukl8JwA"
}
},
{
"subject": "Osaka",
"ext_1_distance": "4958.37",
"ext_1": {
"gmap_x": "135.5022535",
"gmap_y": "34.6937249",
"gmap_type": "roadmap",
"gmap_zoom": "10",
"gmap_place_id": "ChIJ4eIGNFXmAGAR5y9q5G7BW8U"
}
},
{
"subject": "Fukuoka",
"ext_1_distance": "4519.57",
"ext_1": {
"gmap_x": "130.4016888",
"gmap_y": "33.5901838",
"gmap_type": "roadmap",
"gmap_zoom": "9",
"gmap_place_id": "ChIJKYSE6aHtQTURg4c5NplyCvY"
}
}
]
}
info

When you specify order_query with latitude and longitude, distance information (in km) from the specified location will be added to the response as the ext_X_distance field.

Combining with Filter Queries

You can create filters in the format of :D(identifier:latitude:longitude) < 500 to search for content based on distance from the specified location.
While you can use Filter queries alone, ext_X_distance will be calculated based on the position specified in the order_query. Even if you apply filters without sorting, it is recommended to combine them with order_query specified in the format iidentifier==latitude:longitude.

Request Example

  • filter=:D(ext_1:35.17189148918877:136.68933682996803) < 500
  • order_query=ext_1=ASC=35.17189148918877:136.68933682996803

Request URL
https://sitekey.g.kuroco.app/rcms-api/1/maptest?filter=%3AD%28ext_1%3A35.17189148918877%3A136.68933682996803%29%20%3C%20200&order_query=ext_1%3DASC%3D35.17189148918877%3A136.68933682996803

Response Example

{
"list": [
{
"subject": "Osaka",
"ext_1_distance": "120.56",
"ext_1": {
"gmap_x": "135.5022535",
"gmap_y": "34.6937249",
"gmap_type": "roadmap",
"gmap_zoom": "10",
"gmap_place_id": "ChIJ4eIGNFXmAGAR5y9q5G7BW8U"
}
}
]
}
tip

You can also combine multiple conditions.
Example: :D(ext_1:35.17189148918877:136.68933682996803) < 200 or :D(ext_1:35.17189148918877:136.68933682996803) > 500

info

You can set the location information for filter and order_query separately, but the distance returned in the ext_X_distance field will be calculated based on the position specified in the order_query.


Support

If you have any other questions, please contact us or check out Our Slack Community.