Latitude & Longitude in a DB

  • Thread starter David C. Holley
  • Start date
D

David C. Holley

Does anyone have any experience capturing the latitude and longitude of
a location in an a DB? There is the possibility that I may have to
expand a DB of mine to capture the L/L of specific locations and curious
if there's anything special or helpful that I should be aware of.
 
D

Dirk Goldgar

David C. Holley said:
Does anyone have any experience capturing the latitude and longitude
of a location in an a DB? There is the possibility that I may have to
expand a DB of mine to capture the L/L of specific locations and
curious if there's anything special or helpful that I should be aware
of.

I haven't, David, but there have been one or two threads in the past, in
the Access groups -- not necessaarily this one -- where latitude and
longitude were being stored and manipulated. If you search using Google
groups, you should find something.
 
A

Allen Browne

David, I don't have a copy of all the long/lat for world cities if that's
what you need, but Microsoft did have a "neatcode" sample database that had
some demo code useful for working with long/lat--converting degrees,
calculating great arc distance, etc.

Download from:
http://support.microsoft.com/?id=177972
 
P

PC Datasheet

See below from my files ----

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
[email protected]
www.pcdatasheet.com

Use Latitude And Longitude To Find Distance Between Two Points



Const PI As Double = 3.14159265358979
Const Circumference As Double = 40123.648 'kilometers
Const MilesPerKilometer As Double = 0.6214
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
Dim CosArc As Double
Dim Arc As Double
Latitude1 = Radians(Latitude1)
Longitude1 = Radians(Longitude1)
Latitude2 = Radians(Latitude2)
Longitude2 = Radians(Longitude2)
CosArc = (Sin(Latitude1) * Sin(Latitude2)) + _
(Cos(Latitude1) * Cos(Latitude2) * Cos(Longitude1 - Longitude2))
Arc = Degrees(Atn(-CosArc / Sqr(-CosArc * CosArc + 1)) + 2 * Atn(1))
Distance = Arc / 360 * Circumference
If Miles = True Then Distance = Distance * MilesPerKilometer
End Function

Private Function Radians(ByVal Degrees As Double) As Double
Radians = PI * Degrees / 180
End Function

Private Function Degrees(ByVal Radians As Double) As Double
Degrees = Radians / PI * 180
End Function

Testing on New Delhi (28 37 / -77 13)
and
San Francisco ( 37 48 / 122 27)

we get 12380.0276235478 kilometers

National Graphic Family Reference Atlas gives 12380 km ... so you may have
to walk 25 extra yards.

Caution: the second number in latitude and longitude designations are
minutes and must be divided by 60 before being passed to the function as in
Debug.Print Distance(28 + 37 / 60, -77 - 13 / 60, 37 + 48 / 60, 122 + 27 /
60)
(for the two cities above).
Signs must be adjusted for north and south latitude and east and west
longitude ... one positive and the other negative
If one gets to seconds then the numerator will be 3600.
 
T

Tom Lake

David C. Holley said:
Does anyone have any experience capturing the latitude and longitude of a
location in an a DB? There is the possibility that I may have to expand a
DB of mine to capture the L/L of specific locations and curious if there's
anything special or helpful that I should be aware of.

Capture them from where? I use GPS equipment on a glorified PocketPC that
I can sync with my main PC and I analyze the points with an VBA program
using
Access. It's pretty straight forward except for the conversions between
different global
coordinate systems.

Tom Lake
 
D

David C. Holley

Capturing data as in entering it into a table or control on a form. What
datatypes should I use? Inputmasks? Split the Degrees & Minutes into
different fields or keep together? that sort of thing.
 
D

David C. Holley

ActiveSync comes with the PPC. Obviously you've never been introduced to
a PPC. Buy one and you'll fall in love with it faster than your wife,
well maybe not that fast.
 
T

Tim Ferguson

Capturing data as in entering it into a table or control on a form.
What datatypes should I use? Inputmasks? Split the Degrees & Minutes
into different fields or keep together? that sort of thing.

My instinct would be store absolute values of Minutes, using integer
maths to get the Degrees and floating point to get the Seconds:


public function MinutesToString(Longitude As Double) _
As String
' assume that Longitude is not negative; handling E and W
' separately. Otherwise, check use of Int rather than Fix
' because they differ in treatment of negative values
'
dim tempAnswer As String
dim degrees As Integer
dim minutes As Integer
dim seconds As Double

' split out the individual values
degrees = Int(Longitude / 60)
minutes = Int(Longitude - (60 * degrees))
seconds = (Longitude - Int(Longitude))*60

' ... and put them back together again
MinutesToString = Format(degrees, "00") & ":" & _
Format(minutes, "00") & ":" & _
Format(seconds, "00.00")

end function


As usual: this is untested air code and needs to be treated with
caution. The reverse function (and the validation code) is left as an
exercise for the reader...

PS steer well clear of input masks!

Hope that helps


Tim F
 
D

David C. Holley

ARGGGG! I forgot that Lat&Long includes seconds - I was thinking Degrees
and minutes only.
 
Top