Calculate distance between two lat + lng coordinates in React Native?

I have an object containing lat and lng objects of my company. I also have an object containing lat and lng of the user's current location. What I would like to do is iterate over the object with the site location data and calculate the closest to the user's location. I would like to get the kilometers between them, as well as the time spent on the distance.

I was looking at the Google Geometry API , but can't figure out how to use this in React Native, if possible.

My question is what should I do to achieve this? Can I use the Google Geometry API somehow?

Edit: I do not need to do this in the application, preferably, I would like to do this, but if this is not possible, I could just make a selection for my PHP API if it is the best solution for PHP.

+4
source share
2 answers

There are several methods in the npm geolib package https://github.com/manuelbieh/geolib that can help you do this; getDistance, findNearest and orderByDistance.

+6
source

, d = √ ((y2-y1) ^ 2 + (x2-x1) ^ 2). , . , lat long, .

0

Source: https://habr.com/ru/post/1675324/


All Articles