zoukankan      html  css  js  c++  java
  • 2018-2-13-win10-UWP-显示地图

    title author date CreateTime categories
    win10 UWP 显示地图
    lindexi
    2018-2-13 17:23:3 +0800
    2018-2-13 17:23:3 +0800
    Win10 UWP

    微软自带的地图很简单

    第一步引用地图xmlns:Map="using:Windows.UI.Xaml.Controls.Maps"

    这段代码写在<Page>

    然后在Grid 用 Map 来得到 MapControl <Map:MapControl />

    尝试运行

    MapControl

    提示 警告:未指定MapServiceToken

    在功能选位置功能 这里写图片描述

    要获得位置需要权限

    获得权限

    为了获得位置,写一个按钮点击获得位置

    MainPage.xaml.cs

                //需要using Windows.Devices.Geolocation;
                var access = await Windows.Devices.Geolocation.Geolocator.RequestAccessAsync();
                switch (access)
                {
                    case GeolocationAccessStatus.Unspecified:
                        //定位未开启提示是否跳转到 设置 页面            
                        return;
                    case GeolocationAccessStatus.Allowed:           //允许获取          
                        break;
                    case GeolocationAccessStatus.Denied:            //不允许获取位置信息时 给予提示 然后根据情况选择是否跳转到 设置 界面           
                        await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings://privacy/location"));
                        return;
                    default:
                        break;
                }
                var gt = new Geolocator();
                var position = await gt.GetGeopositionAsync();  //以前的position.Coordinate.Latitude 方法在UWP中已经过时,不再推荐使用    
                                                                //var latiude = position.Coordinate.Latitude;   
                map.Center = position.Coordinate.Point;
                map.ZoomLevel = 10;            

    因为 map.Center 说的是 Geopoint,王陈染大神说的是position = await gt.GetGeopositionAsync();类型是Geoposition,结果错误是出现了

    无法将类型“Windows.Devices.Geolocation.Geoposition”隐式转换为“Windows.Devices.Geolocation.Geopoint” appButtonBar

    正确的代码 map.Center = position.Coordinate.Point;

    点击就把地图中心设置在用户位置

    参考:http://www.wangchenran.com

  • 相关阅读:
    Mac Finder 里新建文本
    SourceTree 无法查看组织仓库
    Android Gradle 指定 Module 打包
    Mac 下安装安卓 apk 文件
    Android 瘦身之道 ---- so文件
    Android Google AdMob 广告接入示例
    Java 垃圾回收(GC) 泛读
    [麻雀虽小]记 简易Markdown阅读器 开发全过程
    Git 版本回滚
    线程与进程的区别及其通信方式
  • 原文地址:https://www.cnblogs.com/lindexi/p/12085512.html
Copyright © 2011-2022 走看看