2

I'm developing an application in Excel VBA and I need a way for Google Maps to capture my location automatically (without me having to enter my address). Is this possible through Excel VBA?

Community
  • 1
  • 1
user1863292
  • 21
  • 1
  • 2
  • You can try opening Google Maps via IE and then navigate the button with ID: `id="widget-mylocation"` (it's the bottom right one). – PSotor Jan 24 '17 at 08:14

3 Answers3

2

Hopefully you're still using stackoverflow! When working with google maps I found a quick little URL trick you can use. You can use the URL to setup directions or just automatically track your location.

https://www.google.com/maps/dir/my+location/

This link will automatically upon load, generate a new link (google maps works by loading tons of Div blocks so every section has a generated URL) of your address.

If you want to use the link for directions try the following

https://www.google.com/maps/dir/my+location/Secondary address goes here
MercPls
  • 128
  • 8
0

It's not that automatic. I just ran the following snippet of vba that was part of this post to get a web browser embedded on a worksheet and have found it somewhat finicky but it does eventually work (as per what's shown in the code you need 2 sheets before you run & if it doesn't work you'll have to delete the web browser object and rerun). There are extensive examples available on how to add markers to maps shown on this web browser object (here's one)

 Sub AddWebBroswerToWorksheet()

    Dim myWebBrowser
    Dim wb, doc, x As Long

    Sheet2.Activate

    Set myWebBrowser = Sheet1.OLEObjects.Add(ClassType:="Shell.Explorer.2", _
                       Left:=147, Top:=60.75, Width:=300, Height:=200)

    Set wb = myWebBrowser.Object
    With wb
         .Navigate "about:blank"
         .Document.Open "text/html"
         For x = 1 To 100
           .Document.write "init<br>"
         Next x
         .Document.Close
         .Document.body.Scroll = "no"
    End With

    Sheet1.Activate

    wb.Navigate "http://maps.google.com/maps?q=49.2827,-123.1207"

End Sub

From there you should be able to interact with it via vba to show markers placed on an appropriate web site. In other words it would take a bit of development to get what you want.

Community
  • 1
  • 1
Amorpheuses
  • 1,403
  • 1
  • 9
  • 13
  • Sorry, but this answer does not match my question. I'm already using google api to open google maps. I just need a way to automatically capture my current position in it – user1863292 Jan 24 '17 at 20:50
  • You can just change the url string accordingly to show your latitude and longitude as per the edited answer. – Amorpheuses Jan 24 '17 at 21:55
  • Thanks very much for your attempt, but I believe you did not understand my problem exactly: I only want a way for Google Maps to inform me of my position by inserting this information into the sheet of the excel worksheet. However, I want it to do this automatically, that is, without first needing to inform my position – user1863292 Jan 25 '17 at 01:00
  • Additional note: When I open google maps in my PC's browser, a marker will automatically appear in my location. It is this location that I want to capture through vba excel – user1863292 Jan 25 '17 at 12:03
  • If excel can capture the return url then you might be able to get a hold of that. I have no idea of whether it can or can't. – Amorpheuses Jan 25 '17 at 14:44
  • OK. I think for now this is not possible with VBA eXCEL. Thank you very much for your attention. Strong hug – user1863292 Jan 26 '17 at 00:36
0

You can try something like this:

 Sub GoogleMaps()
   Dim ie As Object
   Dim url As String
   Dim Location

   url = "https://www.google.com/maps/dir/my+location"

   Set ie = CreateObject("InternetExplorer.Application")
   With ie
   .Visible = True
   .navigate url
        .Top = 5
        .Left = 5
        .Height = 1300
        .Width = 1900
       While ie.readyState <> 4

    Wend

    While ie.readyState <> 4
        DoEvents
    Wend
End With
  Set ie = Nothing
   End with
 End Sub

Remember, that what the @MercPls mentioned in the answer above it's a permalink. You can modify it depending on what certainly you need. If you are interested in the different locations or sth you can parse this permalink with some Excel cell values.

Geographos
  • 827
  • 2
  • 23
  • 57