微軟自帶的地圖很簡單
引用地圖`xmlns:Map="using:Windows.UI.Xaml.Controls.Maps"`
寫在`<Page>`
然后在`Grid` 用Map來得到MapControl
`<Map: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](http://www.wangchenran.com)
- 前言
- UWP win10 app 新關鍵字x:Bing
- win10應用 UWP 使用MD5算法
- win10 UWP讀寫文件
- UWP appButtonBar樣式
- C# 6.0 $&quot;Hello {csdn}&quot;
- Win10 UWP xaml 延遲加載元素
- UWP xaml 圓形頭像
- UWP 繪制圖形
- win10 uwp 通知Toast
- win10 UWP 顯示地圖
- win10 uwp 參考
- win10 uwp clone
- win10 uwp 裝機必備應用 含源代碼
- RichEditBox 使用自定義菜單
- win10 UWP FlipView
- win10 UWP 獲取系統信息
- win10 UWP 申請微軟開發者
- win10 UWP button
- win10 UWP Markdown 含源代碼
- win10 UWP 應用設置
- win10 UWP 九幽數據分析
- win10 UWP 圓形等待
- win10 UWP 標題欄后退
- win10 UWP 單元測試
- win10 UWP 你寫我讀
- win10 UWP RSS閱讀器
- win10 UWP MessageDialog 和 ContentDialog
- win10 UWP Hmac
- win10 UWP GET Post
- Win10 UWP Intro to controls and events
- win10 UWP Controls by function
- win10 uwp App-to-app communication 應用通信