问题描述
如何让我在谷歌Android地图API的标记V2变成可点击所以他们要么弹出一个菜单选项或只是开始新的活动?我相信我目前在一个福利局的方法取得了我的应用程序标记。我并没有为它们分配一个名称或方法能够符合要求的code剩下的链接。
How to I make the markers in Android Google Maps API v2 become clickable so they will either bring up a menu with options or just start a new activity? I believe I made the markers in my app currently in a "newb" method. I didn't assign them a name or a method to be able to link it in with the rest of the required code.
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
如果你回答这个问题,请包括标记的样本code引入一个独特的名字,然后被设置为可点击打开一个新的活动。
If you ANSWER this, please include a sample code of a marker being introduced with a unique name and then being set as clickable to open a new activity.
推荐答案
在谷歌Android地图API V2的所有标记是可以点击的。您不需要设置任何附加属性到您的标记。你需要做的是什么 - 是注册标记点击回调到您的GoogleMap和处理点击内的回调:
All markers in Google Android Maps Api v2 are clickable. You don't need to set any additional properties to your marker.What you need to do - is to register marker click callback to your googleMap and handle click within callback:
public class MarkerDemoActivity extends android.support.v4.app.FragmentActivity
implements OnMarkerClickListener
{
private Marker myMarker;
private void setUpMap()
{
.......
googleMap.setOnMarkerClickListener(this);
myMarker = googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
......
}
@Override
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(myMarker))
{
//handle click here
}
}
}
这篇关于谷歌地图API V2:如何使标志物可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!