1

I am parsing a polygon from a KML file to an MKMap and when a user add an annotation (point) on the map I need to calculate the shortest displacement between the annotation to the polygon (not to on of the polygon points but to his bounds).

Heres an example :

enter image description here

I have the coordinates for each point of the polygon and I have the coordinates of the annotation.

What I had in mind is to run through all the points coordinates and try to calculate the perpendicular line from the annotation to each line and then compare the displacements, then calculate all the displacements to the polygon points from my annotation and choose the smallest displacement but I am sure there is a much better and simpler solution.

I was searching for some ready to use framework but with no success.

Vadim F.
  • 881
  • 9
  • 21
  • Does this infer right from your explanation -- Nearest edge coordinate of polygon to the annotation? (distance can be calculated later) – Amber K Apr 18 '19 at 06:54
  • Yes it is exactly, I will edit the question in a moment, thanks – Vadim F. Apr 18 '19 at 06:57
  • May I know what is the data type for your polygon? is it CGMutablePath? – Amber K Apr 18 '19 at 07:01
  • I am receiving the polygon from the parse as MKOverlay and converting it to array of MKMapPoint but I guess I can convert it to CGMutablePath as well. Should I add the code? – Vadim F. Apr 18 '19 at 07:07
  • https://stackoverflow.com/questions/10983872/distance-from-a-point-to-a-polygon – Dávid Kaszás Apr 18 '19 at 07:07
  • @DávidKaszás I have already tried those solutions but none of them satisfied my needs, the polygon consist from a lot of point and I wouldn't want to iterate over all of them – Vadim F. Apr 18 '19 at 07:13

0 Answers0