5 Replies Latest reply on Feb 1, 2018 11:38 PM by Chris McClellan

# Nearest Location Finder for set of lat-longs

I am trying to find nearest location from given lat long.

That’s determined by the Spherical Cosine Law, or the Haversine Formula which is mentioned below.

I have used this formula in SQL to determine distance between lat1-long1 and lat2-long2.

lat1 and lat2 are the latitude and longitude which is in my table . The issue is this formula works only for one set of lat2- long2  but I want to implement this for a set of lat-long which is dynamic and is coming from the excel sheet. I am unable to blend or join the two sources as they don't have any common field.

How can I do that ? Any ideas?

• ###### 1. Re: Nearest Location Finder for set of lat-longs

What's your source data look like ? I was doing this the other day in Tableau, but it's much easier if you have an identifier for each point that you want to link.

What I actually did was have a set of lat/long co-ordinates in Excel for each Region.  I joined the data on to itself with a <> join and that way I could calculate the distance between any region (user-chosen) to any other Region.

• ###### 2. Re: Nearest Location Finder for set of lat-longs

I have two data sources. First is the main data source in which I have Latitude,Longitude of entire city along with economic data for each lat long. Now, In tableau I'm plotting lat longs on the filled map and showing data in the table. I want to add another source in which users will give their lat/longs which may match upto 2 or 3  decimal places with the existing ones but are not exactly same. And then I will create buffers around those lat/longs on the map of given radius and show the respective data of those buffers only.

• ###### 3. Re: Nearest Location Finder for set of lat-longs

Sounds very doable, I wouldn't like to see users entering a lat/long though, give them a list of cities/locations and they can choose that with a distance calculation as well.

• ###### 4. Re: Nearest Location Finder for set of lat-longs

Could you elaborate ? Lets assume that I will give my lat/long as a filter to the user .If the user chooses 3 set of Lat/Longs and radius of 2 km, how can I draw 3 buffers of 2km each around those points at the same time?

• ###### 5. Re: Nearest Location Finder for set of lat-longs

Ah sorry, I didn't catch it before that you wanted to draw buffers around it ..

You could try these links :