Re: Finding the closest address.

848 0
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

I have a list of dealers and their addresses. I want people to give me their address and find the closest dealer to their location.

4 Replies 4
7 - App Architect
7 - App Architect

Hi @identifysolutio - if you're asking for a geolocation extension, I'm not sure Airtable is the best tool to use. If you're looking for users to submit their information via form, that is very simple to create and distribute. Could you provide more context on how this might work?

Hey @CJSmith ,

Yeah I am well seasoned in Airtable. So I am actually using to do all of the form collection into Airtable. That side, yes, is the easy part. 

Now that I have collected a users addy, I am trying to see how I can recommend them the closest dealer to physically go to to buy our products.  

So It is like I want to measure distances to the dealers and recommend the best one in their area.

I would also then like to alert that dealer to the new lead coming there way. 

7 - App Architect
7 - App Architect

Off the top of my head, a formula to match ZIP codes of users and dealers would be the simplest solution (not  without a fair amount of drawbacks), but I'll leave it to the community since this is a bit out of my wheelhouse. Good luck!

You have to retrieve geopoints for each of your dealers, then get latitude and longitude of user address

this script can give you a distance between 2 points. note that it just measure a shortest distance between points on a globe, no matter which roads are available. I just tried it for 2 random points, and it almost match distance measure on google maps, difference is 0,2%

// 33837 Davenport FL 28.19084, -81.59108
// 38316 Bradford TN 36.06851, -88.8149

const earthRadius = 6371000; //meters
const toRad=dgr=>dgr/180*Math.PI
const dist=(lat1,lng1,lat2,lng2)=>{
  const dLat = toRad(lat2-lat1);
  const dLng = toRad(lng2-lng1);
  const a=Math.sin(dLat/2)*Math.sin(dLat/2)+
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  return Math.round(earthRadius * c)/1000+' km'
output.text(dist(28.19084, -81.59108, 36.06851, -88.8149))
// 1108.264 km , google maps says its 1110 km