如何在 Google Maps for Android API v2 上显示我的位置 [英] How to display my location on Google Maps for Android API v2

查看:32
本文介绍了如何在 Google Maps for Android API v2 上显示我的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找答案,但在任何论坛问题中都没有人能够提供帮助.我已经搜索了教程.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 上显示我的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆