Hey, is this the right place to ask about an issue...
# community-help
i
Hey, is this the right place to ask about an issue I have using geopoint search with polygon. I see it working sometimes and somehow not working on others.
j
Yes it is. Could you share the search query you’re using?
i
let me get the search params array
Copy code
"{"q":"*","query_by":"title,address,listingId","page":1,"filter_by":"location:(20.643101970825, -105.2271453804, 20.647860850082, -105.22630853119, 20.646696243606, -105.22096557083, 20.646897038462, -105.22055787506, 20.646756482091, -105.22010726395, 20.641214441604, -105.22118014755, 20.641234521826, -105.22208136978, 20.642057808619, -105.22328299942)"}"
I see on the documentation that polygon should be
The polygon's points must be defined in a *counter-clockwise (i.e. anti-clockwise) direction*.
how can I verify the direction? πŸ€”
j
That's likely the issue... You can add one marker at a time on a map visually, for each of the points and make sure that each marker added is in a counter-clockwise direction, compared to the previous one
A shortcut is also to go to maps.google.com, then entering your first lat long, then click on get directions and then add the other lat longs one at a time as additional destinations
And make sure every marker that is added is in a counter-clockwise direction compared to the previous marker.
i
mhmm
j
In this case, I noticed that the 2rd lat/long is in the clockwise-direction
i
on the typesense response there is a
request_params
and it returns this:
{"collection_name":"properties","per_page":10,"q":"*"}
it does not mention the filter.
j
Yup that's expected.
request_params
in the response contains just enough information to render most search UIs and not all the params that were sent
i
mhmm when the search works it returns the same
let me try what you mention on the map to check the direction, so I should see the points going from right to left.
πŸ‘ 1
this query
Copy code
"{"q":"*","query_by":"title,address,listingId","page":1,"filter_by":"location:(20.647836009729, -105.22632746033, 20.643036969737, -105.22716430954, 20.642032967319, -105.22321609787, 20.641149439709, -105.2214994841, 20.641591204155, -105.22109178833, 20.646832038996, -105.22008327774)"}"
does work
So the issue is the order in which I draw on the map
if I draw clockwise I get the polygon on that order.
if I draw not clockwise the search work
now need to figure out how to verify order at runtime before sending the search. πŸ˜…
Copy code
$polygonSource = $sourceSearch->polygon;
                    if ($polygonSource[0]->lat < $polygonSource[1]->lat) {
                        $polygonSource = array_reverse($polygonSource);
                    }
that is all to get the polygon on the right direction. Thanks! Cool product! Congrats!
πŸ™Œ 1
j
Nice, thank you for sharing!
@Ignacio mind opening a github issue describing your original issue and then adding your solution as a response? I think others searching in the future would find it useful.
i
sure
πŸ™ 1
Thanks for looking at it.
πŸ‘ 1