获取我的位置与setMyLocationEnabled()方法 [英] Fetching my location with setMyLocationEnabled() method
问题描述
我试图使用 setMyLocationEnabled()
方法来获得地图中我的位置。有这种方法没有问题,我也用 setMyLocationButtonEnabled()
键,一切都很好。
I am trying to get my location in a map using the setMyLocationEnabled()
method. There is no problem with this method, I have also used setMyLocationButtonEnabled()
and everything is good.
但是,当我在地图上按一下按钮,我不明白的蓝点,表示我的位置。
But when I click on the button in the map, I don't get the "blue dot" that indicates my location.
你能告诉我这个问题可能是什么?
Can you tell me what the problem could be?
推荐答案
首先,您应该声明一个匿名内部类,实现 Google.OnMyLocationChangeListener
,或者你可以只是实现它在你的主类。比方说,你图的实例被称为地图
。您必须设置监听器,像这样: map.setOnMyLocationChangeListener(本)
。然后,你将不得不做这样的事情:
First, you should either declare an anonymous inner class, that implements Google.OnMyLocationChangeListener
, or you could just implement it in your main class. Let's say the instance of your map is called map
. You will have to set the listener, like this: map.setOnMyLocationChangeListener(this)
. Then, you will have to do something like this:
@Override
public void onMyLocationChange(Location location) //inherited from the interface you implemented
{
//do your thing, the variable "location" holds everything you need
}
这篇关于获取我的位置与setMyLocationEnabled()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!