C
C
Coder3212017-05-04 14:34:55
Google
Coder321, 2017-05-04 14:34:55

How to calculate the nearest location?

There is a variable myCoordinate and there is an array allCoordinates

const myCoordinate = {
    "lat": 53.9256183,
    "lng": 27.512342
}

const allCoordinates = [{
    "lat": 53.9256183,
    "lng": 27.512342
}, {
    "lat": 23.92234183,
    "lng": 54.534342
}, {
    "lat": 54.9226183,
    "lng": 32.5122342
}]

How can I calculate the closest coordinates to myCoordinate from an array? Can you use Google Maps for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Khodyrev, 2017-05-04
@maximkou

Have a look at the Haversine formula: https://en.wikipedia.org/wiki/Haversine_formula
Example (there is an implementation in JS): www.movable-type.co.uk/scripts/latlong.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question