1
votes

Is there a proven formula to match up slightly different lat/lng values to a street address without submitting both of them to a Geocoding service (since we've already done so and don't want to make a second api call).

eg. The following coordinates are for the same street address (55 Church Street zip code 07505), but one set points to the building and the other to the street.

lat : 40.9170109 long: -74.1702248

lat: 40.9171216 long: -74.1704997

So is there a commonly used formula we can use, perhaps something to the effect of , match up the first 4 decimal places or subtract the two lat values and the two long values and if the difference is less than x , it is most likely the same street address. These are just my ideas based on the definitions of lat/long, but we are looking for something proven, perhaps even the industry standard formula if anything like that exists.

1

1 Answers

0
votes

For measuring distances in close proximity Pythagoras or a variation of this is adequate. You may have heard of the Haversine formula but it overkill for close proximities.

pyth

For locations near the equator pythagoras is adequate but as we move away from the equator it becomes less accurate due to the convergence of the meridians(longitude) as we approach the poles. This is compensated in the Equirectangular() function

As you tag Google Maps the following javascript functions can be used. Note d is in meters.

For your example Pyth() gives 33meters and Equirectangular() 26meters. For completeness haversine() also give 26meters.

function toRad(Value) {
/** Converts numeric degrees to radians */
return Value * Math.PI / 180;
}

function Pyth(lat1,lat2,lng1,lng2){
    var x = toRad(lng2-lng1) ;
    var y = toRad(lat2-lat1);
    var R = 6371000; // gives d in meters
    var d = Math.sqrt(x*x + y*y)* R;
    return d;
 }


function Equirectangular(lat1,lat2,lng1,lng2){
    var x = toRad(lng2-lng1) * Math.cos(toRad(lat1+lat2)/2);
    var y = toRad(lat2-lat1);
    var R = 6371000; // gives d in meters
    var d = Math.sqrt(x*x + y*y)* R;
    return d;
}