c# - 如何根据 xml 文件数据添加 GMap 标记?
问题描述
我想要实现的是,当用户按下“上传”按钮时,它将检索打开的xml文件的所有纬度和经度,并且在读取xml文件坐标后,地图会自动在地图上添加GMap标记.
我尝试从 xml 文件中检索纬度和经度数据并将纬度和经度文本添加到列表中,但我不确定如何将其添加到 Gmap 并在文件加载时将其显示在地图上。我不确定我是否做得对,请指导我..
这是来自表单类的按钮:
private void Form1_Load(object sender, EventArgs e)
{
//Bing map
gmap.MapProvider = BingHybridMapProvider.Instance;
GMaps.Instance.Mode = AccessMode.ServerOnly;
//Paris, France
gmap.Position = new PointLatLng(48.8566, 2.3522);
gmap.ShowTileGridLines = false;
gmap.ShowCenter = false;
gmap.DragButton = MouseButtons.Left;
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog opnfd = new OpenFileDialog();
opnfd.Filter = "(*.xml) | *.xml";
if (opnfd.ShowDialog() == DialogResult.OK)
{
TweetEvent tweetevent = new TweetEvent();
tweetevent.GetLocation();
GMapOverlay markers = new GMapOverlay("markers");
GMapMarker marker = new GMarkerGoogle(
new PointLatLng(lat, lng), //Not sure how to add lats and lons from xml file into here
GMarkerGoogleType.blue_pushpin);
gmap.Overlays.Add(markers);
markers.Markers.Add(marker);
}
这是 TweetEvent 类中的类函数
public override void GetLocation()
{
//Load xml file
XDocument xmldoc = XDocument.Load(@"C:\Users\JACK\source\repos\LINQ_Learn\LINQ_Learn\xmlFile.xml");
XNamespace nlle = "http://www.aab.org/lifelogevents";
XNamespace nSoapenv = "http://www.w3.org/2001/12/soap-envelope";
//Retrieve latitudes and longitudes when tweet tag is encountered
var tweetlatlons = from tweetTag in xmldoc.Descendants(nlle + "tweet").Descendants(nlle + "location")
select new { Lat = tweetTag.Element(nlle + "lat").Value, Lon = tweetTag.Element(nlle + "long").Value };
List<string> getlatslons = new List<string>();
//Add all the lats and lons into the List
foreach (var latslons in tweetlatlons)
{
string lati = latslons.Lat;
string lngi = latslons.Lon;
getlatslons.Add(lati);
getlatslons.Add(lngi);
}
}
这是xml文件:
soapenv:Letter xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope" soapenv:encodingStyle="http://www.w3.org/2001/12/soap-encoding" >
<soapenv:Body xmlns:lle="http://www.aab.org/lifelogevents" >
<lle:Event>
<lle:eventid>ID1</lle:eventid>
<lle:tweet>
<lle:text>This is some tweet in my day</lle:text>
<lle:location>
<lle:lat>123</lle:lat>
<lle:long>456</lle:long>
</lle:location>
</lle:tweet>
</lle:Event>
<lle:Event>
<lle:eventid>ID2</lle:eventid>
<lle:instagram-post-update>
<lle:text>This is some status update in my day</lle:text>
<lle:location>
<lle:lat>789</lle:lat>
<lle:long>987</lle:long>
</lle:location>
</lle:instagram-post-update>
</lle:Event>
<lle:Event>
<lle:eventid>ID3</lle:eventid>
<lle:tweet>
<lle:text>This is some tweet in my day</lle:text>
<lle:location>
<lle:lat>434</lle:lat>
<lle:long>554</lle:long>
</lle:location>
</lle:tweet>
</lle:Event>
</soapenv:Body>
</soapenv:Letter>
解决方案
推荐阅读
- android - android MPAndroidChart BarChart中点中心的中心x轴标签
- database - 具有多个关系的 laravel 数据库查询
- flutter - itemCount 长度留出空间
- mongodb - 从本地 PC 连接到 docker 容器中的数据库
- react-native - RN spyOn click 方法不是上下文 setState 等类型的可分配参数
- jupyter-notebook - 在 Jupyter 中下载文件:Windows 上的 wget?
- oop - 同一个结构的多个接口
- wordpress - 将属性添加到
WordPress中的标签 - c# - C++ 互操作的限制(隐式 PInvoke)
- ios - Youtube_player_flutter 不在 iOS 设备上播放视频