65.9K
CodeProject 正在变化。 阅读更多。
Home

Windows Phone 中的必应地图

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.60/5 (6投票s)

2012年8月9日

CPOL
viewsIcon

40490

downloadIcon

1569

在 Windows Phone 7 中使用必应地图

引言

如今,移动应用程序越来越受欢迎。它们最重要的优势是移动性,这得益于像必应地图这样的功能得以实现。这使得它们更加动态,并为客户提供许多备受赞赏的服务。必应地图可以帮助查找用户的位置并向其显示道路和距离。

使用代码

此应用程序将向您展示如何在工具箱中使用 Map 控件。将其拖放到页面后,将在 .xaml 文件中添加以下代码。

<my:Map Height="543" HorizontalAlignment="Left" 
  Name="map1" VerticalAlignment="Top"
  Width="480" Margin="-12,0,0,0" />

之后,我们需要添加以下 using 语句才能开始使用 Map 功能

using Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Maps;
using System.Device.Location;

现在您可以从 .cs 文件操作 map1。我们将使用以下代码添加一个简单的 Pushpin

//declare the Pushpin 
Pushpin p = new Pushpin();
//define it's graphic properties 
p.Background = new SolidColorBrush(Colors.Yellow);
p.Foreground = new SolidColorBrush(Colors.Black);
//where to put the Pushpin 
p.Location = new GeoCoordinate(10, 36);
//What to write on it
p.Content = "You are here";
//now we add the Pushpin to the map
map1.Children.Add(p);
map1.SetView(new GeoCoordinate(10, 36, 200), 9); 

我添加了一些图标来使用缩放、使用道路模式和带有标签的航拍模式

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" Opacity="0.9">
        <shell:ApplicationBarIconButton IconUri="/Icons/plus.png" Text="Zoom In" Click="zoomIn_click"/>
        <shell:ApplicationBarIconButton IconUri="/Icons/minus.png" Text="Zoom out" Click="zoomOut_click"/>
        <shell:ApplicationBarIconButton IconUri="/Icons/A.png" Text="Aerial mode" Click="Aerial_click"/>
        <shell:ApplicationBarIconButton IconUri="/Icons/R.png" Text="Road mode" Click="Road_click"/>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="Choose my position" Click="chooseMyPosition_click"/>
            <shell:ApplicationBarMenuItem Text="Locate Me" Click="locateMe_click"/>
            <shell:ApplicationBarMenuItem Text="Set Pushpin" Click="setPin_click"/>
            <shell:ApplicationBarMenuItem Text="Add Pushpin" Click="addPin_click"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>  

这行代码用于在页面之间导航

NavigationService.Navigate(new Uri("/ChooseMyPosition.xaml", UriKind.Relative)); 

一些快照

如果您需要更多信息,请告诉我。

您可能想在 MSDN 上查看我的其他示例 这里

© . All rights reserved.