用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c#代码库

c#

2020-07-29 作者:朱文波30举报

[c#]代码库

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
//新添加命名空间  
using System.Net;
using System.IO;
using System.Security.Permissions;  //交互JS
 
namespace MapWinForms
{
    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
 
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        //载入加载地图
        private void Form1_Load(object sender, EventArgs e)
        {
            //本地文件 MapWinForms\bin\Debug
            string url = Application.StartupPath + "\\BaiMapJS.html";
            string file = <a target=_blank href="file:///E:\\WinFormBaiduMap\\test.html">file:///E:\\WinFormBaiduMap\\test.html</a>;
            webBrowser1.ScriptErrorsSuppressed = true;   //屏蔽js相关错误
            webBrowser1.Navigate(url);                   //导航显示本地HTML文件
        }
 
        //城市搜索
        private void button1_Click(object sender, EventArgs e)
        {
            /**
                * 参考资料:
                * http://bbs.csdn.net/topics/390935011
                * http://www.sufeinet.com/thread-7897-1-1.html
                */
 
            //C#调用JS函数
            string city;
            if (comboBox1.SelectedIndex == -1)
            {
                city = "北京";
            }
            else 
            {
                city = comboBox1.SelectedItem.ToString();
            }
            webBrowser1.Document.InvokeScript("LoadMap", new object[] { city });
        }
 
        //车间搜索
        private void button2_Click(object sender, EventArgs e)
        {
            string city;
            if (comboBox1.SelectedIndex == -1)
            {
                city = "北京";
            }
            else
            {
                city = comboBox1.SelectedItem.ToString();
            }
            webBrowser1.Document.InvokeScript("SearchCarMap", new object[] { city });
        }
 
        //附近热点搜索
        private void button3_Click(object sender, EventArgs e)
        {
            string city;
            if (comboBox1.SelectedIndex == -1)
            {
                city = "北京";
            }
            else
            {
                city = comboBox1.SelectedItem.ToString();
            }
            string key;
            if (comboBox2.SelectedIndex == -1)
            {
                key = "学校";
            }
            else
            {
                key = comboBox2.SelectedItem.ToString();
            }
            webBrowser1.Document.InvokeScript("SearchNearbyMap", new object[] { city, key });
        }
 
        //当前位置定位
        private void button4_Click(object sender, EventArgs e)
        {
            webBrowser1.Document.InvokeScript("LocateMyPlcae", new object[] { });
        }
 
        //附近餐馆
        private void button5_Click(object sender, EventArgs e)
        {
            webBrowser1.Document.InvokeScript("GetResMyPlace", new object[] { });
        }
 
        //导航
        private void button6_Click(object sender, EventArgs e)
        {
            webBrowser1.Document.InvokeScript("RouteMyPlace", new object[] { });
        }
    }
}


分享到:
更多

网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。