简体   繁体   中英

How can I determine if the current position is within a KML-defined area?

I have some KML data which defines an area on a map, such as the following:

131.0764742247829,-15.80786022929951,0 132.6357700620065,-16.54895727734661,0
134.1119108999971,-17.28040233069844,0 135.8545033459996,-18.1298170074137,0 
137.7396886168202,-19.07860187595016,0 140.011948401144,-20.18462043802856,0 
142.3114600417346,-21.19369381963822,0 144.1566045495202,-22.15731684591415,0

带有KML定义区域的地图

I'd like to determine within my iOS application if the user's current location is inside of this defined area. How can I do this?

If you know the center and radius of the circle then it is quite easy.

CLRegion *circle = [CLRegion initCircularRegionWithCenter:centerCoordinate radius:circleRadius identifier:@"myCircle"];

BOOL doesItContainMyPoint = [circle containsCoordinate:myLocation];

Update based on revised question

I've never tried this, but couldn't you create a UIBezierPath with your points (you don't have to actually draw the bezier path) and then use UIBezierPath's - (BOOL)containsPoint:(CGPoint)point to test for inclusion?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM