如何获取点击的地理位置在C#中兵地图上 [英] how to get the geolocation of a click on a bing map in C#

查看:444
本文介绍了如何获取点击的地理位置在C#中兵地图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是有可能得到在那里我在C#中点击一个兵地图点的地理位置?

is it possible to get the geolocation of the point where i clicked on a bing Map in c#?

推荐答案

好吧,既然你在WinRT中是在C#中,你正在使用Bing地图的Windows Store应用控制。
添加映射到你的XAML标记:

Alright, since you're in WinRT in C#, you're using the Bing Maps Windows Store App control. Add the map into your XAML markup:

<Page
    x:Class="Win8PublicApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:m="using:Bing.Maps">
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <m:Map Name="MyMap" Credentials="YOURKEY"/>
    </Grid>
</Page>



然后,你可以做到这一点补充图钉你点击其中:

Then you can do this to add pushpin where you have clicked:

public MainPage()
{
    this.InitializeComponent();

    this.MyMap.PointerPressedOverride += MyMap_PointerPressedOverride;
}

void MyMap_PointerPressedOverride(object sender, PointerRoutedEventArgs e)
{
    Bing.Maps.Location l = new Bing.Maps.Location();
    this.MyMap.TryPixelToLocation(e.GetCurrentPoint(this.MyMap).Position, out l);
    Bing.Maps.Pushpin pushpin = new Bing.Maps.Pushpin();
    pushpin.SetValue(Bing.Maps.MapLayer.PositionProperty, l);
    this.MyMap.Children.Add(pushpin);
}

这篇关于如何获取点击的地理位置在C#中兵地图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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