如何使用C#在WebBrowser控件中显示Google地图 [英] How to display Google Maps in WebBrowser Control using C#

查看:209
本文介绍了如何使用C#在WebBrowser控件中显示Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public partial class GetLocation : Form
    {
        delegate void DecodePositionEvent();

        GeoPostion geoPosition;
        public GetLocation()
        {
            InitializeComponent();

            geoPosition = new GeoPostion();
        }

        private void DecodePosition()
        {
            try
            {
                if (geoPosition != null)
                {
                    mapBrowser.Navigate(string.Format("https://maps.google.com/maps?q=" +
                    geoPosition.GeoLatitude + "," + geoPosition.GeoLongtitude));
                }
            }
            catch(Exception error)
            {
                MessageBox.Show(error.Message, "Error Loading Map.");
            }
        }

        private void GetLocation_Load(object sender, EventArgs e)
        {
            try
            {
                GeoPostion.GetGeoPositions();

                computersCmBox.BindingContext = new BindingContext();
                computersCmBox.DataSource = GeoPostion.AssetGeoPos;
                computersCmBox.DisplayMember = "ComputerName";
                computersCmBox.ValueMember = "Staff_ID";
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Error Loading Geo-Position");
            }
        }

        private void computersCmBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(computersCmBox.SelectedIndex > 0)
            {
                geoPosition = GeoPostion.AssetGeoPos.Find(geo => geo.Staff_ID.Equals(computersCmBox.SelectedValue));

                if(geoPosition != null)
                {
                    if (Utilities.IsStringEmpty(geoPosition.ComputerName).Equals(false) & computersCmBox.SelectedValue.Equals(-1).Equals(false))
                    {
                        Utilities.AssignData(new string[] { geoPosition.GeoLatitude, geoPosition.GeoLongtitude, geoPosition.DateStamp + ": " + geoPosition.TimeStamp },
                            latitudeTxt, longtitudeTxt, timeStampTxt);

                        new DecodePositionEvent(DecodePosition).Invoke();
                    }
                    else
                    {
                        mapBrowser.Navigate("about:blank");
                        Utilities.ClearControl(latitudeTxt, longtitudeTxt, timeStampTxt);
                    }
                }
            }
        }

        private void closeBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Dispose();
        }
    }
}





粗体线是问题的根源,因为错误我得到的是:



您似乎使用的是不受支持的浏览器。

旧的浏览器可能会使您的安全性受到威胁,速度很慢不适用于较新的Google地图功能。要访问Google地图,您需要更新到现代浏览器。



The bolded line is the source of the problem because the error I get is below:

You seem to be using an unsupported browser.
Old browsers can put your security at risk, are slow and don't work with newer Google Maps features. To access Google Maps, you'll need to update to a modern browser.

推荐答案

您好,



问题是webbrowser控件使用Internet Explorer 7.你必须告诉计算机使用ie11。



遵循这个教程:http://weblog.west-wind.com/posts/2011/May/ 21 / Web-Browser-Control-Specifying-the-IE-Version



这里有更多信息http://weblog.west-wind.com/posts/2011/May/21/Web-浏览器控制 - 指定IE版本





你必须在windows注册表中添加一个密钥然后重启你的申请。这对我有用。



希望这会有所帮助。



LG
Hi,

the problem is that webbrowser control uses Internet Explorer 7. You have to tell the computer to use ie11.

Follow this tutorial: http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

Here's more information http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version


you have to add a key in the windows register and then restart your application. That worked for me.

Hope this helps.

LG


这篇关于如何使用C#在WebBrowser控件中显示Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆