[AccessD] Weird problem with lat/long distance function

jack drawbridge jackandpat.d at gmail.com
Thu Aug 23 13:18:28 CDT 2012


Mark there is no formatting in your text.

There are samples in vba at http://www.cpearson.com/excel/LatLong.aspx

There may be issues with results where points are very close to each other.
What sort of difference in coords do you have?
How do you represent coordinates?

jack

On Thu, Aug 23, 2012 at 1:04 PM, Mark A Matte <markamatte at hotmail.com>wrote:

>
> Hello All,
> I have been using the following for some time...today I am comparing
> coordinates that are very close...and I am getting 'weird'
> results/errors.(A2007)
> I entered the lat/long numbers in the code below to show the behavior I am
> seeing.
> With these coordinates...the CosArc = 1...but the IF statement below
> executes the ELSE.
> Unless the absolute value of 1 is NOT 1...why would this not work?
> Thanks,,,  Mark
> 'If Abs(CosArc) = 1 Then'    Arc = PI'Else
> Public Function Distance( _    ByVal Latitude1 As Double, _    ByVal
> Longitude1 As Double, _    ByVal Latitude2 As Double, _    ByVal Longitude2
> As Double, _    Optional Miles As Boolean) As Double'courtesy Lyle
> Fairfield'assumes we are getting latitude-longitude'as degrees with
> fractions expresed as decimals'if minutes-seconds then use Sexagesimal
> function to convertDim CosArc As DoubleDim Arc As DoubleLatitude1 =
> Radians(41.70900431)Longitude1 = Radians(-83.585444)Latitude2 =
> Radians(41.7090043053031)Longitude2 = Radians(-83.5854439996183)'Latitude1
> = Radians(Latitude1)'Longitude1 = Radians(Longitude1)'Latitude2 =
> Radians(Latitude2)'Longitude2 = Radians(Longitude2)
> CosArc = (Sin(Latitude1) * Sin(Latitude2)) + _    (Cos(Latitude1) *
> Cos(Latitude2) * Cos(Longitude1 - Longitude2))
> '***PROBLEM HERE***If Abs(CosArc) = 1 Then    Arc = PIElse    Arc =
> Atn(-CosArc / Sqr(-CosArc * CosArc + 1)) + 2 * Atn(1)End IfDistance = Arc /
> PI / 2 * CircumferenceIf Miles = True Then Distance = Distance *
> MilesPerKilometerDistance = Round(Distance, 2)End Function
> Private Function Radians(ByVal degrees As Double) As Double    Radians =
> PI * degrees / 180End Function
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list