Example: Searching Locations with Polygons
The listing search available in Spark® API provides shape based search criteria for geographic locations.
Step 1: Authentication
This example expects that you have already obtained an OAuth 2 authorization token to access a user's data. Read more on our OpendID Connect Authentication and OAuth 2 Authorization.
Step 2: Define a polygon
For an example, we will use a polygon from popular culture which would find some listings of repute (if they exist).
Bermuda Triangle Coordinates:
25.774252°N, 80.190262°W
18.466465°N, 66.118292°W
32.321384°N, 64.75737°W
Step 3: Searching for listings inside the polygon
Since the shape is a triangle, we'll use the polygon
search function for the
Location
field with this filter:
Location Eq polygon('25.774252 -80.190262,18.466465 -66.118292,32.321384 -64.75737')
$ curl "https://sparkapi.com/v1/v1/listings?_filter=Location+Eq+polygon%28%2725.774252+-80.190262%2C18.466465+-66.118292%2C32.321384+-64.75737%27%29&_select=Latitude%2CLongitude" -H "Authorization: OAuth MY_OAUTH2_ACCESS_TOKEN"
{
"D": {
"Success": true,
"Results": [
{
"Id": "20100000000000000000000000",
"ResourceUri": "/v1/listings/20100000000000000000000000",
"StandardFields": {
"Latitude"=>25.0,
"Longitude"=>-71.0
}
}
]
}
}