I use FSL.PolygonUtils from Field service package, to check if a latitude/longitude is within a service territory.
I want to separate my territories with record types. The problem is that API doesn't support it, as it give me back the closest territory level without considering record types(I can have overlapping territories, so that's why i user record type based on the request).
I am doing this query, to check all the territory where that coordinate could land :
SELECT Id, Name, FSL__Description__c, FSL__Color__c, FSL__KML__c, FSL__Service_Territory__c, FSL__Service_Territory__r.FSL__TerritoryLevel__c,
FSL__Mi_La__c, FSL__Ma_La__c, FSL__Mi_Lo__c, FSL__Ma_Lo__c FROM FSL__Polygon__c
WHERE FSL__Service_Territory__c != null
AND FSL__Mi_La__c <= :lat
AND FSL__Ma_La__c >= :lat
AND FSL__Mi_Lo__c <= :lon
AND FSL__Ma_Lo__c >= :lon
AND FSL__Service_Territory__r.RecordType.DeveloperName =:requestType LIMIT 10000
For the result I will get, I can extract the KML file, that look like
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Style id="Great Toronto CoreStyle">
<LineStyle>
<width>1</width>
</LineStyle>
<PolyStyle>
<color>80E5881E</color>
</PolyStyle>
</Style>
<Placemark>
<name>Great Toronto</name>
<styleUrl>#Great TorontoStyle</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-79.33801613769532,43.767698789150835,0
-79.33589182815554,43.75804421098782,0
-79.33401139070469,43.75160149776085,0
-79.33366517681036,43.74814593102189,0
-79.3325336326381,43.7426243489531,0
-79.33226037535184,43.73924674477029,0
-79.32456269368157,43.7408808698677,0
...
Did any of you already had the same request, as based on that polygon coordinates, check if a lat/long is within it?
Thanks for your help