Excel VBA 和谷歌地图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41817393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 11:56:41  来源:igfitidea点击:

Excel VBA and Google Maps

excel-vbagoogle-maps-markersvbaexcel

提问by user1863292

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?

我正在 Excel VBA 中开发一个应用程序,我需要一种让 Google 地图自动捕获我的位置的方法(无需我输入我的地址)。这可以通过 Excel VBA 实现吗?

回答by MercPls

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.

希望你还在使用 stackoverflow!在使用谷歌地图时,我发现了一个可以使用的快速小 URL 技巧。您可以使用 URL 设置路线或仅自动跟踪您的位置。

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.

此链接将在加载时自动生成您地址的新链接(谷歌地图通过加载大量 Div 块来工作,因此每个部分都有一个生成的 URL)。

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

如果您想使用链接获取路线,请尝试以下操作

https://www.google.com/maps/dir/my+location/Secondary address goes here

回答by Mariusz Krukar

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.

请记住,@MercPls 在上面的答案中提到的是永久链接。您可以根据需要修改它。如果您对不同的位置或某事感兴趣,您可以使用一些 Excel 单元格值解析此永久链接。

回答by Amorpheuses

It's not that automatic. I just ran the following snippet of vba that was part of this postto 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)

这不是自动的。我只是运行了以下 vba 片段,它是这篇文章的一部分,以将 Web 浏览器嵌入到工作表中,并发现它有些挑剔,但最终确实可以工作(根据代码中显示的内容,在运行之前您需要 2 张工作表 &如果它不起作用,则必须删除 Web 浏览器对象并重新运行)。有大量关于如何向此 Web 浏览器对象上显示的地图添加标记的示例(这里有一个

 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.

从那里你应该能够通过 vba 与它交互以显示放置在适当网站上的标记。换句话说,要得到你想要的东西需要一些发展。