Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 3 of 3

Find latitude and longitude of map corners with VBA

This is a discussion on Find latitude and longitude of map corners with VBA within the Development forums, part of the MapPoint Desktop Discussion category; Hi, I use the following code to place pushpins on a map and zoom in the area. Do Until oWorksheet2.Cells(i, ...

  1. #1
    Well is offline Junior Member White Belt
    Join Date
    May 2007
    Location
    Montreal
    Posts
    11

    Find latitude and longitude of map corners with VBA

    Hi,

    I use the following code to place pushpins on a map and zoom in the area.

    Do Until oWorksheet2.Cells(i, 1) = 0
    sStation = oWorksheet2.Cells(i, 1)

    Set oStation = oMap.FindResults(sStation).Item(1)
    oMap.AddPushpin oStation
    i = i + 1
    Loop
    oMap.DataSets.ZoomTo

    I also use the code http://www.mp2kmag.com/a13--kohl.extract.lat.lon.mappoint.html to find latitude and longitude of each pushpin. However, I also need to know what is the latitude and longitude of each corner of my map. How can I do that with VBA code.

    Thanks for help

    A.Ouellet

    p.s: I am a french Canadian. I am sorry for all possible English mistakes.

  2. #2
    Mattys Consulting's Avatar
    Mattys Consulting is offline Senior Member Black Belt
    Join Date
    Dec 2002
    Posts
    1,040

    Re: Find latitude and longitude of map corners with VBA

    Well ... I might do it like this:

    Type LATLONGPOINT
    x As Double
    y As Double
    End Type

    Dim CNW As LATLONGPOINT
    Dim CNE As LATLONGPOINT
    Dim CSW As LATLONGPOINT
    Dim CSE As LATLONGPOINT

    Dim NWC As MapPointCtl.Location
    Dim NEC As MapPointCtl.Location
    Dim SWC As MapPointCtl.Location
    Dim SEC As MapPointCtl.Location

    Dim dblLatNWC As Double
    Dim dblLongNWC As Double

    Dim dblLatSWC As Double
    Dim dblLongSWC As Double

    Dim dblLatNEC As Double
    Dim dblLongNEC As Double

    Dim dblLatSEC As Double
    Dim dblLongSEC As Double

    Public Function OutputDimensions()

    'Mattys Consulting

    Dim dblWidthTop As Double, dblWidthBottom As Double
    Dim dblHeightWest As Double, dblHeightEast As Double

    CNW.x = 0: CNW.y = 0
    CSW.x = 0: CSW.y = oMap.Height
    CNE.x = oMap.Width: CNE.y = 0
    CSE.x = oMap.Width: CSE.y = oMap.Height

    On Error Resume Next

    Set NWC = oMap.XYToLocation(CNW.x, CNW.y)
    Set SWC = oMap.XYToLocation(CSW.x, CSW.y)
    Set NEC = oMap.XYToLocation(CNE.x, CNE.y)
    Set SEC = oMap.XYToLocation(CSE.x, CSE.y)

    If (dblLatNWC = 0 And dblLongNWC = 0) = False Then

    'CalcPos courtesy of Gilles Kohl
    CalcPos oMap, NWC, dblLatNWC, dblLongNWC
    CalcPos oMap, SWC, dblLatSWC, dblLongSWC
    CalcPos oMap, NEC, dblLatNEC, dblLongNEC
    CalcPos oMap, SEC, dblLatSEC, dblLongSEC

    'Add pushpins if desired
    Set NWC = oMap.GetLocation(dblLatNWC, dblLongNWC)
    Set SWC = oMap.GetLocation(dblLatSWC, dblLongNWC)
    Set NEC = oMap.GetLocation(dblLatNWC, dblLongNEC)
    Set SEC = oMap.GetLocation(dblLatSWC, dblLongNEC)

    dblWidthTop = oMap.Distance(NWC, NEC)
    dblWidthBottom = oMap.Distance(SWC, SEC)

    dblHeightWest = oMap.Distance(NWC, SWC)
    dblHeightEast = oMap.Distance(NEC, SEC)

    End If

    End Function

    If you have any questions, just ask.

    Mike Mattys

  3. #3
    Well is offline Junior Member White Belt
    Join Date
    May 2007
    Location
    Montreal
    Posts
    11

    Re: Find latitude and longitude of map corners with VBA

    Thank you Mike. Very helpful

    A.Ouellet

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. find Location Name through Longitude Latitude
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 02-17-2010, 05:24 AM
  2. Using longitude and latitude to find adress
    By Edward_Carnby in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 07-22-2008, 09:12 AM
  3. How to get latitude and longitude
    By ma2005pp in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 09-28-2005, 02:57 AM
  4. Latitude and Longitude
    By virgilar in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 03-21-2005, 02:01 PM
  5. NMEA latitude/longitude and mappoint latitude/longitude
    By muurman in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 11-22-2003, 05:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96