这次准备来一篇扫盲贴,废话不说了,直接进主题吧。
第五步:在cs文件中敲入代码
第六步:编译,运行,效果如图
第一步:新建一个WPF 应用程序项目如图,
第二步:在项目里添加一个HTML文件,具体就是右键“解决方案资源管理器”中的项目名---“添加”----“新建项”----“HTML页”,如图,
第三步:在新增的html文件里敲进代码
<html>
<head>
<title></title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type ="text/javascript">
var map;
function InitializeMap()
{
//var latlng = new google.maps.LatLng(-34.397, 150.644);
var latlng = new google.maps.LatLng(22.84, 108.33);
var myOptions = {
zoom: 9,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker = new google.maps.Marker
(
{
position: new google.maps.LatLng(22.84, 108.33),
map: map,
title: '南宁市'//这是鼠标悬停内容
}
);
var infowindow = new google.maps.InfoWindow({
content: '南宁市'//这是现实具体内容
});
google.maps.event.addListener(marker, 'click', function() {
// Calling the open method of the infoWindow
infowindow.open(map, marker);
});
//getBoundary();
}
</script>
</head>
<body οnlοad="InitializeMap()">
<div id ="map" style="width: 100%; position: absolute; height: 100%">
</div>
</body>
</html>
第四步:在xaml文件中敲入代码
<Window x:Class="GMapTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<WebBrowser x:Name="webBrowser1"/>
</Grid>
</Window>
第五步:在cs文件中敲入代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace GMapTest
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
Basic ds = new Basic();
webBrowser1.Navigate(new Uri(System.Environment.CurrentDirectory + @"/HTMLPage1.htm", UriKind.RelativeOrAbsolute));
webBrowser1.ObjectForScripting = ds;
}
}
[System.Runtime.InteropServices.ComVisibleAttribute(true)]//将该类设置为com可访问
public class Basic
{
public static string name;
public string Name
{
get { return name; }
set { name = value; }
}
public void ClickEvent(string str)
{
this.Name = str;
}
}
}
第六步:编译,运行,效果如图