Marker only within FeatureCollection

Anyone know how can I make user can only put marker on the inside of FeatureCollection boundary.
image

What you need to do is dependant on your existing code (which you did not share with the community).

You probably can test if coordinates are within a Polygon either using


DistanceToFeature( mapFeature , centroids )

Computes the distance between the Polygon and the given mapFeature . If centroids is true , the computation is done between the centroids of the two features. Otherwise, the distance will be computed between the two features based on the closest points. Further, when centroids is false , this method will return 0 if the Polygon intersects or contains the mapFeature . If an error occurs, this method will return -1.

DistanceToPoint( latitude , longitude , centroid )

Computes the distance between the Polygon and the given latitude and longitude . If centroids is true , the distance is computed from the center of the Polygon to the given point. Otherwise, the distance is computed from the closest point on the Polygon to the given point. Further, this method will return 0 if centroids is false and the point is in the Polygon . If an error occurs, -1 will be returned.


to determine if the 'marker' (actually the coordinates of the proposed Marker) are within or without the boundaries of the polygon and then use an If..then conditional to determine what to do based on the result.

See Polygon . You probably will need to poll the 'contents' of the FeatureCollection to determine which item to use for your calculation.

Hi thanks for the reply, but can you check why I got error in my code .
So this is the design part


And this is my code for checking if the marker is within the FeatureCollection

I expect because you did not check if the Marker is within a polygon (map feature) within the FeatureCollection.

Perform a DoIt on the FeatureCollection to expose what the FeatureCollection contains.

when centroids is false , this method will return 0 if the **Polygon** intersects or contains the mapFeature if you are trying to find out if it is in a particular polygon.

This also should work:

DistanceToFeature( mapFeature , centroids )

Computes the distance between the Marker and the given mapFeature . If centroids is true , the computation is done between the centroids of the two features. Otherwise, the distance will be computed between the two features based on the closest points. Further, when centroids is false , this method will return 0 if the Marker intersects or contains the mapFeature . If an error occurs, this method will return -1.

I gave this a try, using the distance to point and Map Tap At Point

Works fine,for me, when tapping outside of the polygon, but returns nothing (doesn't change the label text to 0) when tapping inside the polygon

Ah, it works, and returns 0 for a marker's lat and lon. So distanceToPoint needs coordinates from a feature....

Thanks for the solution, but if I use this way than I have to set all 6 of my location.
image
Is there a way to just calculate the distanceToPoint or DistanceToFeature of "FeatureCollection1"

I have try putting the marker within the polygon but the result is an error.

inoutFeatures

or, to get distance distInMeters

3 Likes

Oh thank you so much that works well with my system :grin:. But does that mean I have to do all this block for all the other states.
image
Is it possible if I can make all the states in one list. And if the marker is located in one of the state, it will state "in"

Something like this should work (sorry I didn't have a geoJson file to hand)

1 Like

Hi there thank you so much, I have already find the solution. Your solution works but one problem is that the program will run until the last of the list which is "New England" although the marker is INSIDE "Maine" or "Vermont" it will not change the "Label1" to "In" because the program will compare until the last of the list.

Therefore, I just realize that I can create a function where once the marker is within any of the list, it will go to the function and change the "Label1" to "In".
Thank you so much TIMAI2 and here is my coding which is working.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.