从GoogleMaps检索完整的URL

时间:2019-06-11 21:54:02

标签: web browser chromium cefsharp chromium-embedded

我在一个大型WinForms应用程序中使用的是CefSharp版本43.0.0,我在其中将参数传递给Google Maps,即源地址和目标地址,以便生成熟悉的地图和逐个路线指示。这样就可以了。但是,我需要捕获用户通常通过使用Google Maps获得的更长,更完整的URL。

如果我采用相同的参数,即简单的“来源”和“目标”来寻址并将其插入任何其他浏览器,则Google Maps将返回一个更长,更完整的URL,其中包含纬度和经度地址。 (请注意下面显示的示例)。

当我使用Chromium Web浏览器(CEF)将参数传递给Google时,我得到了地图,但没有完整的URL。

有人可以建议使用CEF时如何获得所需的URL吗?请记住,这是WinForms应用程序,而不是Web应用程序。

https://www.google.com/maps/dir/2230+Picton+Pkwy,+Akron,+OH+44312/1680+E+Waterloo+Rd,+Akron,+OH+44306/@41.0149182,-81.48249,14z/data=!3m1!4b1!4m13!4m12!1m5!1m1!1s0x88312b00dd84936f:0xb1901f583967068e!2m2!1d-81.467646!2d41.003081!1m5!1m1!1s0x88312bb5f325ca6b:0x48697b37d442dccf!2m2!1d-81.4676985!2d41.0246252

这是到目前为止我尝试过的,如以下代码所示。我将参数从一种形式传递到包含Chromium浏览器的形式。

它会创建带有方向的地图,但不会返回如果我在其他浏览器(如Firefox,Chrome等)中手动输入相同的参数,则会收到更长,更完整的URL。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CefSharp.WinForms;
using CefSharp;

namespace myApplication
{
    public partial class myDirectionFinder : Form
    {
        public ChromiumWebBrowser browser;

        public myDirectionFinder()
        {
            InitializeComponent();

            CefSettings settings = new CefSettings();
            if (!CefSharp.Cef.IsInitialized)//Cef can only be initialized once.     Using 'Cef.IsInitialized' guards against an exception.
            {
                CefSharp.Cef.Initialize(settings);
            }
        }

        private void myDirectionFinder_FormClosing(object sender,     FormClosingEventArgs e)
        {
            browser = null;
        }

        private void myDirectionFinder_Load(object sender, EventArgs e)
        {
            browser = new ChromiumWebBrowser(txtUrlPasser.Text) { Dock = DockStyle.Fill };
            txtFinalAddr.Text = "";
            txtFinalAddr.Text = browser.Address.ToString();
            pnlBrowser.Controls.Add(browser);
        }
    }
}

0 个答案:

没有答案
相关问题