zoukankan      html  css  js  c++  java
  • windows phone 使用bing map 服务

    http://msdn.microsoft.com/en-us/library/ff941093(v=vs.92)

    http://msdn.microsoft.com/en-us/library/ee681887.aspx

    以上是两个msdn上关于bing map使用的介绍。前一个是手机端的api,后者是silverlight的。手机端的和网页silverlight使用方式基本上一致,只是有几个地方不太一样。使用的时候需要注意下。

    下面简单概括一下:

    要在界面里插入上图一样的地图元素,只需要在.xaml 中插入一个map控件:

    <Grid x:Name="GridMap" Grid.Row="1" Margin="12,0,12,0">
    <m:Map Name="UserGeoMap" CredentialsProvider="your credentials"
    ZoomBarVisibility="Visible"
    />
    </Grid>

    在此之前,你需要登录https://www.bingmapsportal.com/ 注册一个bing map key , 替换上文中的"your credentials".

    xaml的命名空间也要稍加修改:

    <phone:PhoneApplicationPage
    x:Class="IMove.Transportation_Pages.MyGeoMap"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True"
    xmlns:m="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps" xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit">

    并且导入两个库就可以了:

    其他操作,例如如何放大、缩小,如何切换卫星图层,都在第一个链接中有提到。

    如果想在地图上根据gps坐标划一条路径怎么办呢? 那么就在.cs文件中加入一个画路径的函数吧。

    MapPolyline 指在map上的折线,只要指定每个点的坐标,就可以把这条折线画到地图上。
    private void DrawRoutes()
            {
                
                Color routeColor = Colors.Blue;
                SolidColorBrush routeBrush = new SolidColorBrush(routeColor);
                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Stroke = routeBrush;
                routeLine.Opacity = 0.65;
                routeLine.StrokeThickness = 5.0;
    
                List<LocationInfoUnit> coors = new List<LocationInfoUnit>();
            // LocationInfoUnit 就是包含 Latitude 和 Longitude的简单的类
                for(int i=0;i<4;i++)
                {
                    coors.Add(new LocationInfoUnit(39.9780032923817+i*0.01, 116.303654518087));
                }
    
                foreach (var p in coors)
                {
                    routeLine.Locations.Add(new System.Device.Location.GeoCoordinate(p.Latitude, p.Longitude));
                }
                UserGeoMap.Children.Clear();
                MapLayer myRouteLayer = new MapLayer();            
                UserGeoMap.Children.Add(myRouteLayer);
    
                myRouteLayer.Children.Add(routeLine);
    
                LocationRect rect = new LocationRect(routeLine.Locations[0], 0.05, 0.05);
    
                UserGeoMap.SetView(rect);
            }
    

      

  • 相关阅读:
    linux开放防火墙端口方法
    Node.js 构建TCP服务
    React高阶组件
    在create-react-app 中启用装饰器语法
    Redux
    微信小程序组件与组件之间的通讯
    微信小程序网络请求
    微信小程序的页面导航跳转
    sqoop2启动job报错
    sqoop2启动client异常
  • 原文地址:https://www.cnblogs.com/sylvanas2012/p/bing_map.html
Copyright © 2011-2022 走看看