在地图中添加图钉
在C#中,添加一个图钉就是创建一个Pushpin对象,设置它的位置,然后将它添加到地图中。在XAML中也可以实现。很明显,XAML为你提供了更快捷的方式,但其实哪种方式都不复杂。
XAML
<map:Pushpin Location="40.1449, -82.9754" FontSize="30" Background="Orange" Content="1" />
C#
Pushpin pushpin = new Pushpin();
Location location = new Location();
location.Latitude = 40.1449;
location.Longitude = -82.9754;
pushpin.Location = location;
pushpin.Background = new SolidColorBrush(Colors.Orange);
pushpin.Content = "1";
pushpin.FontSize = 30;
MapControl.Children.Add(pushpin);
<map:Pushpin Location="40.1449, -82.9754" FontSize="30" Background="Orange" Content="1" />
C#
Pushpin pushpin = new Pushpin();
Location location = new Location();
location.Latitude = 40.1449;
location.Longitude = -82.9754;
pushpin.Location = location;
pushpin.Background = new SolidColorBrush(Colors.Orange);
pushpin.Content = "1";
pushpin.FontSize = 30;
MapControl.Children.Add(pushpin);
在上面的例子中,无论哪种方式,都会将一个图钉钉到我的办公室,在8800 Lyra Drive, Columbus可以找到。在我的程序中看起来是这样的:

如果你想知道如何将你的地址转换为经纬度,请参见我的这篇Silverlight 31日谈系列中的文章。它包含了地理地址编码以及你要在手机程序中所做的内容。