問題描述
我一直在尋找答案,但在任何論壇問題中都沒有人能夠提供幫助.我已經搜索了教程.API 指南 說:
I've looked high and low for an answer on this, and no one, in any forum question has been able to help. I've searched through the tutorials. The API Guide says:
我的位置"按鈕出現在屏幕的右上角僅當啟用我的位置"圖層時.
The My Location button appears in the top right corner of the screen only when the My Location layer is enabled.
所以我一直在尋找這個我的位置"圖層,但找不到任何東西.如何在 Google 地圖上顯示我的位置?
So I've been looking for this My Location layer and have been unable to find anything. How do I show my location on a Google Map?
推薦答案
API 指南完全錯了(真的是 Google?).使用 Maps API v2,您無需啟用圖層來顯示自己,只需調用您使用地圖創建的 GoogleMaps 實例即可.
The API Guide has it all wrong (really Google?). With Maps API v2 you do not need to enable a layer to show yourself, there is a simple call to the GoogleMaps instance you created with your map.
Google 文檔
Google 提供的實際文檔可以為您提供答案.你只需要
The actual documentation that Google provides gives you your answer. You just need to
// map is a GoogleMap object
map.isMyLocationEnabled = true
// map is a GoogleMap object
map.setMyLocationEnabled(true);
并觀看奇跡發生.
只需確保您擁有位置權限,并且在 API 級別在運行時請求它23(男)或以上
Just make sure that you have location permission and requested it at runtime on API Level 23 (M) or above
這篇關于如何在 Google Maps for Android API v2 上顯示我的位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!