dcsimg
Results 1 to 10 of 10

Thread: Google Map using Lat, Long from VB in Access Form Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    6

    Google Map using Lat, Long from VB in Access Form Question

    I have a VB script I use in my Access form that when a user enters in a LATITUDE and LONGITUDE, the button in the form will open Google Maps to that location:

    Code:
         
    sLink = "http://maps.google.com/maps?f=q&hl=en&q="
    Application.FollowHyperlink sLink & LATITUDE & " " & LONGITUDE
    That works just fine. However, I'm trying to get the map to now open in satellite mode not the basic default map mode and not sure how I can go about doing this.

    I know the parameter is:
    Code:
    basemap=satellite
    And I know that it seems you need the /maps/@?api=1 in there for it to work. I can open google maps using the Google Developers guide to open a specific Lat/Long in satellite mode by using something like:

    Code:
         
    https://www.google.com/maps/@?api=1&map_action=map&center=39.856242, -104.974871&zoom=12&basemap=terrain
    Application.FollowHyperlink sLink
    But I can't for the life of me figure out how to use the LONGITUDE and LATITUDE user defined variables for each record in the Access Form.

    I've tried all sorts of combinations with the above code with my current code and came seem to get it to work.

    Any help would be great...

  2. #2
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,231

    Re: Google Map using Lat, Long from VB in Access Form Question

    Hi,

    this is from a VB6 Program, might help

    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMAXIMIZED = 3
    
    Private Sub cmdGoogle_Click()
    ' The basic map URL without the address information.
    Const URL_BASE As String = "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=@TYPE@"
    
    Dim addr As String
    Dim url As String
    
    txtAdress.Text = "39.856242, -104.974871"
        ' A very simple URL encoding.
        addr = txtAddress.Text
        addr = Replace$(addr, " ", "+")
        addr = Replace$(addr, ",", "%2c")
    
        ' Insert the encoded address into the base URL.
        url = Replace$(URL_BASE, "@ADDR@", addr)
    
        ' Insert the proper type.
        Select Case cboGoogle.Text '<-- is a combobox
            Case "Map"
                url = Replace$(url, "@TYPE@", "m")
            Case "Satellite"
                url = Replace$(url, "@TYPE@", "h")
            Case "Terrain"
                url = Replace$(url, "@TYPE@", "p")
        End Select
    
        ' "Execute" the URL to make the default browser display it.
        ShellExecute ByVal 0&, "open", url, _
            vbNullString, vbNullString, SW_SHOWMAXIMIZED
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,272

    Re: Google Map using Lat, Long from VB in Access Form Question

    i use this format for satelite with a pin:
    https://maps.google.com/?q=48.178343...93482&z=20&t=k

    google encourages to sign up with them with a developer key but the above does (still) work without. i think even with the dev key, which afair is free, it is not that easy to get the pin at the right location, requires some code around. if you decide to use the above, be aware that google might cut support for that one day to the other.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    6

    Re: Google Map using Lat, Long from VB in Access Form Question

    Quote Originally Posted by ChrisE View Post
    Hi,

    this is from a VB6 Program, might help

    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMAXIMIZED = 3
    
    Private Sub cmdGoogle_Click()
    ' The basic map URL without the address information.
    Const URL_BASE As String = "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=@TYPE@"
    
    Dim addr As String
    Dim url As String
    
    txtAdress.Text = "39.856242, -104.974871"
        ' A very simple URL encoding.
        addr = txtAddress.Text
        addr = Replace$(addr, " ", "+")
        addr = Replace$(addr, ",", "%2c")
    
        ' Insert the encoded address into the base URL.
        url = Replace$(URL_BASE, "@ADDR@", addr)
    
        ' Insert the proper type.
        Select Case cboGoogle.Text '<-- is a combobox
            Case "Map"
                url = Replace$(url, "@TYPE@", "m")
            Case "Satellite"
                url = Replace$(url, "@TYPE@", "h")
            Case "Terrain"
                url = Replace$(url, "@TYPE@", "p")
        End Select
    
        ' "Execute" the URL to make the default browser display it.
        ShellExecute ByVal 0&, "open", url, _
            vbNullString, vbNullString, SW_SHOWMAXIMIZED
    End Sub
    regards
    Chris
    I'm not that great with VB, but looked at the code and tried to figure out how to get it to work. Again it's using set Lat, Long in the code rather than using a user input variable from the FORM.

    That's where I'm having the issue. As mentioned this works using my 2 user inputs (LATITUDE and LONGITUDE) from the Form, but just figure there has to be an easy way to get the "&basemap=satellite" added to the code below after the (& LATITUDE & " " & LONGITUDE), but I'm just not able to.
    Code:
       sLink = "http://maps.google.com/maps?f=q&hl=en&q="
       Application.FollowHyperlink sLink & LATITUDE & " " & LONGITUDE
    I've tried various ways such as this with no luck
    Code:
        sat = "&basemap=satellite"
         sLink = "http://maps.google.com/maps?f=q&hl=en&q="
         Application.FollowHyperlink sLink & LATITUDE & " " & LONGITUDE & sat

  5. #5
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,231

    Re: Google Map using Lat, Long from VB in Access Form Question

    Hi,

    rather than using a user input variable from the FORM.
    what variable(s) are on the Form

    well it's been a long time since i worked on a Access Form, here I changed the code a little

    Code:
    Option Compare Database
    Option Explicit
    
    
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMAXIMIZED = 3
    
    
    Private Sub cmdgoogle_Click()
    ' The basic map URL without the address information.
    Const URL_BASE As String = "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=@TYPE@"
    
    Dim addr As String
    Dim url As String
    
    Me.txtAdress.SetFocus
    
    txtAdress.Text = "39.856242, -104.974871"
        ' A very simple URL encoding.
        addr = txtAdress.Text
        addr = Replace$(addr, " ", "+")
        addr = Replace$(addr, ",", "%2c")
        
        ' Insert the encoded address into the base URL.
        url = Replace$(URL_BASE, "@ADDR@", addr)
    
    Me.cbogoogle.SetFocus
        ' Insert the proper type.
        Select Case cbogoogle.Text '<-- is a combobox
            Case "Map"
                url = Replace$(url, "@TYPE@", "m")
            Case "Satellite"
                url = Replace$(url, "@TYPE@", "h")
            Case "Terrain"
                url = Replace$(url, "@TYPE@", "p")
        End Select
    
        ' "Execute" the URL to make the default browser display it.
        ShellExecute ByVal 0&, "open", url, _
            vbNullString, vbNullString, SW_SHOWMAXIMIZED
    End Sub
    It worked and I came out at Thornton,Colorado (with your values 39.856242, -104.974871)
    changing the combobox to Map or Satellite worked also

    EDIT:
    @Mods
    I think this should be moved to Office Dev. Forum


    regards
    Chris
    Last edited by ChrisE; Sep 17th, 2018 at 09:51 AM.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    6

    Re: Google Map using Lat, Long from VB in Access Form Question

    The FORM has two fields. one is txt_Long which populates the LONGITUDE in the actual table and the other is txt_Lat for the LATITUDE.

    So I need the Google Maps to display the current records Lat/Long in satellite mode.

    I do have another field that combines the LATITUDE and LONGITUDE called txt_Google which is just using the Control Source:
    Code:
    =[LATITUDE] & ", " & [LONGITUDE]
    This is what my original Google Map button uses (without the satellite version at least). I don't need it to display as a combo box as it always needs to be in satellite mode.

    I'll try your new code as is, and see if I can get that to work, and then see if I can break it down to only have the satellite mode showing...

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    6

    Re: Google Map using Lat, Long from VB in Access Form Question

    The way I'm thinking it should work is something like this:

    Code:
    sLink = "https://www.google.com/maps/@?api=1&map_action=map&basemap=satellite&f=q&hl=en&q="
    
    Application.FollowHyperlink sLink & TXT_Google
    Based off my existing code. As stated it needs that @api?=1 in there I think. The above code seems to take the correct coordinates and opens in satellite mode, but just doesn't go to the proper location at all which is what's stumbling me.

    (I also realized it was shorter to use the TXT_Google instead of the (& LATITUDE & " " & LONGITUDE) for the FollowHyperlink for simplicity.

    However, that @api?=1 seems to be a problem.

    Tried your code and I got an error with the Me.txtAdress.SetFocus, but maybe I need to set that to my existing TXT_Google? (Me.TXT_Google.SetFoucs)?
    Last edited by pjordanco; Sep 17th, 2018 at 10:32 AM.

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    6

    Re: Google Map using Lat, Long from VB in Access Form Question

    UPDATE:

    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMAXIMIZED = 3
    
    
    Const URL_BASE As String = "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=h"
    Dim addr As String
    Dim url As String
    
    Me.TXT_Google.SetFocus
        addr = TXT_Google.Text
        addr = Replace$(addr, " ", "+")
        addr = Replace$(addr, ",", "%2c")
        url = Replace$(URL_BASE, "@ADDR@", addr)
        
    ShellExecute ByVal 0&, "open", url, _
        vbNullString, vbNullString, SW_SHOWMAXIMIZED
    Ok yes doing it like this worked. Thank you. Just seems though it's a lot more complex than it should be. I will play around with it and see if I can somehow use the format of the
    Code:
    "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=h"
    and try and get it to work under my original format and see.

    Either way, this does solve the problem. Thank you...

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    6

    Re: Google Map using Lat, Long from VB in Access Form Question

    UPDATE:

    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMAXIMIZED = 3
    
    
    Const URL_BASE As String = "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=h"
    Dim addr As String
    Dim url As String
    
    Me.TXT_Google.SetFocus
        addr = TXT_Google.Text
        addr = Replace$(addr, " ", "+")
        addr = Replace$(addr, ",", "%2c")
        url = Replace$(URL_BASE, "@ADDR@", addr)
        
    ShellExecute ByVal 0&, "open", url, _
        vbNullString, vbNullString, SW_SHOWMAXIMIZED
    Ok yes doing it like this worked. Thank you. Just seems though it's a lot more complex than it should be. I will play around with it and see if I can somehow use the format of the
    Code:
    "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=h"
    and try and get it to work under my original format and see.

    Either way, this does solve the problem. Thank you...

    UPDATE:
    (I figured it out using the code you used, so it did help me get the format correct)
    Code:
        sLink = "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ie=UTF8&t=h&ttype=&q="
        Application.FollowHyperlink sLink & LATITUDE & " " & LONGITUDE
    Last edited by pjordanco; Sep 17th, 2018 at 01:02 PM.

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,118

    Re: Google Map using Lat, Long from VB in Access Form Question

    Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width