Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

在Windows Phone 7的Bing Map控件中使用 Nokia Maps

From Wiki
Jump to: navigation, search
SignpostIcon HereMaps 99.png
SignpostIcon WP7 70px.png
Article Metadata

代码示例
兼容于
文章
翻译:
最后由 hamishwillee 在 16 Jul 2013 编辑

本文阐述了怎样在Windows Phone上使用Nokia Maps。

Contents

简介

在这篇文章中,我们将介绍怎样使用Nokia tiles而不是使用Bing tiles实现在Windows Phone上使用Nokia Maps。

新建项目

  1. 打开Microsoft Visual Studio Express 2010并创建一个名为NokiaMaps的'Application Project'。
  2. 选择O.S 7.1

References

右击Reference选择Add reference添加下列引用

  1. Microsoft.Phone.Controls.Maps
  2. Microsoft.Phone.Controls
  3. System.Device

NokiaMapTile.cs

  1. 将源码Media:NokiaMapsWP7.zip中的NokiaMapsTile.cs复制到项目目录中
  2. 右击'Project Name' -> 'Add' -> 'Exsiting element'选择NokiaMapsTile.cs添加到项目
  3. 根据项目命名空间修改NokiaMapsTile.cs中的命名空间NokiaMaps
  4. 提供Nokia Maps token 和 app id,不是强制性的但是有用的
private string token  = "<YOUR NOKIA MAPS TOKEN>";
private string app_id = "<YOUR NOKIA MAPS APP ID>";

MainPage.xaml

打开MainPage.xaml并向项目中添加Map组件。添加以下代码:

xmlns:NokiaMapsSource="clr-namespace:NokiaMaps"    
xmlns:MSPCMCore="clr-namespace:Microsoft.Phone.Controls.Maps.Core;assembly=Microsoft.Phone.Controls.Maps"
<my:Map Height="634" HorizontalAlignment="Left" Name="map" VerticalAlignment="Top" Width="456"
CredentialsProvider="<YOU BING CREDENTIAL>"
CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" ScaleVisibility="Visible">
<my:Map.Mode>
<MSPCMCore:MercatorMode/>
</my:Map.Mode>
 
<my:MapTileLayer Name="street" Margin="0,0,0,32" Height="647" Width="475">
<my:MapTileLayer.TileSources>
<NokiaMapsSource:NokiaMapsTile TileTypes="Street"/>
</my:MapTileLayer.TileSources>
</my:MapTileLayer>
 
<my:MapTileLayer Visibility="Collapsed" Name="wateroverlay" Margin="0,0,0,32">
<my:MapTileLayer.TileSources>
<NokiaMapsSource:NokiaMapsTile TileTypes="WaterOverlay"/>
</my:MapTileLayer.TileSources>
</my:MapTileLayer>
 
<my:MapTileLayer Visibility="Collapsed" Name="hybrid" Margin="0,0,0,32">
<my:MapTileLayer.TileSources>
<NokiaMapsSource:NokiaMapsTile TileTypes="Hybrid"/>
</my:MapTileLayer.TileSources>
</my:MapTileLayer>
 
<my:MapTileLayer Visibility="Collapsed" Name="satellite" Margin="0,0,0,32">
<my:MapTileLayer.TileSources>
<NokiaMapsSource:NokiaMapsTile TileTypes="Satellite"/>
</my:MapTileLayer.TileSources>
</my:MapTileLayer>
 
<my:MapTileLayer Visibility="Collapsed" Name="physical" Margin="0,0,0,32">
<my:MapTileLayer.TileSources>
<NokiaMapsSource:NokiaMapsTile TileTypes="Physical"/>
</my:MapTileLayer.TileSources>
</my:MapTileLayer>
 
</my:Map>
<Button Content="Zoom In" Height="72" HorizontalAlignment="Left" Margin="6,535,0,0" Name="buttonZoomIn" VerticalAlignment="Top" Width="207" Click="buttonZoomIn_Click" />
<Button Content="Zoom Out" Height="72" HorizontalAlignment="Left" Margin="243,535,0,0" Name="buttonZoomOut" VerticalAlignment="Top" Width="207" Click="buttonZoomOut_Click" />

Zoom control

打开MainPage.xaml.cs添加以下代码:

private void buttonZoomIn_Click(object sender, RoutedEventArgs e)
{
double zoom;
zoom = map.ZoomLevel;
map.ZoomLevel = ++zoom;
}
 
private void buttonZoomOut_Click(object sender, RoutedEventArgs e)
{
double zoom;
zoom = map.ZoomLevel;
map.ZoomLevel = --zoom;
}

现在,你已经准备好了开始使用Nokia Maps!

Adding Markers

MapLayer m_PushpinLayer = new MapLayer();
map.Children.Add(m_PushpinLayer);
 
// Reasonable stab at center of Seattle metro area
map.SetView(new GeoCoordinate(41.89001, 12.495346), 10);
 
// Create and Add a few push pins
Pushpin pushpin1 = new Pushpin();
pushpin1.Background = new SolidColorBrush(Colors.Red);
pushpin1.Location = new GeoCoordinate(45.463983, 9.187946); // Milan
 
Pushpin pushpin2 = new Pushpin();
pushpin2.Background = new SolidColorBrush(Colors.Green);
pushpin2.Location = new GeoCoordinate(37.066684, 15.282555); // Siracusa
 
Pushpin pushpin3 = new Pushpin();
pushpin3.Background = new SolidColorBrush(Colors.Blue);
pushpin3.Location = new GeoCoordinate(37.102357, 15.124986); // Solarino
 
m_PushpinLayer.AddChild(pushpin1, pushpin1.Location);
m_PushpinLayer.AddChild(pushpin2, pushpin2.Location);
m_PushpinLayer.AddChild(pushpin3, pushpin3.Location);
 
map.ZoomLevel = 6;

享用Windows Phone上的Nokia Maps:-) File:NokiaMapsWP7.zip

This page was last modified on 16 July 2013, at 07:13.
97 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×