[Solved] How do I find/add Map Markers Nearest to the User (Haversine formula)

I wanted to share a fun solultion that I created for another project

https://us-central1-scorecard-x.cloudfunctions.net/returnDistance?long1=45&lat1=-83&long2=22&lat2=-40&miles=true

You can feed it the lat and long for both location 1 and 2, true/false for returning miles or KM. this will return an object that has the distance!

Quick and easy. each response takes apx 44 seconds when the function is warm. If you are doing a 1 off calculation, it takes about a second.

i also replicated it in cloudflare for fun. always faster than the one above

2 Likes