I know the center coordinates and an array of all coordinates of a polygon. How can I find out which coordinate is the furthest coordinate for the center point with Javascript?
Center of bounds:
lat: -13.647141573542923lng: 109.75651876851946
Coordinates of the 4 polygon paths:
"lat:-9.10209673872643 , lng: 108.10546875"
"lat:-16.97274101999901 , lng: 91.58203125"
"lat:-17.644022027872722 , lng: 120.234375"
"lat:-8.407168163601074 , lng: 120.41015625"
The canonical way of doing things:
p_i
and calculate the distance d_i
to the center point.p_k
with d_k = max_j d_j
will be the point you are looking for.For distance calculation keep in mind that you can save yourself any operation that won't change the information "further away than", i.e. in euclidic coordinates you could save yourself taking the square root. Also multiplications by any constant can be omitted for this (as long as you don't need to actually know the distance, but only the information which point is the furthest away).