Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

Latitude & Longitude in a DB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David C. Holley - 02 Sep 2005 03:22 GMT
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.
Dirk Goldgar - 02 Sep 2005 03:47 GMT
> 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.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Allen Browne - 02 Sep 2005 04:31 GMT
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

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> 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.
PC Datasheet - 02 Sep 2005 05:39 GMT
See below from my files ----

Signature

                                       PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
                             resource@pcdatasheet.com
                                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.

Tom Lake - 02 Sep 2005 11:09 GMT
> 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
PC Datasheet - 02 Sep 2005 13:44 GMT
Tom,

How do you sync the Pocket PC with your main PC?

Thanks!

Steve

>> 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
[quoted text clipped - 9 lines]
>
> Tom Lake
David C. Holley - 02 Sep 2005 14:09 GMT
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.

> Tom,
>
[quoted text clipped - 17 lines]
>>
>>Tom Lake
David C. Holley - 02 Sep 2005 14:06 GMT
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.

>>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
[quoted text clipped - 9 lines]
>
> Tom Lake
Tim Ferguson - 02 Sep 2005 17:46 GMT
> 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
David C. Holley - 02 Sep 2005 20:00 GMT
ARGGGG! I forgot that Lat&Long includes seconds - I was thinking Degrees
and minutes only.

>>Capturing data as in entering it into a table or control on a form.
>>What datatypes should I use? Inputmasks? Split the Degrees & Minutes
[quoted text clipped - 35 lines]
>
> Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.