显示工具栏,谷歌地图标记自动 [英] Display toolbar for Google Maps marker automatically
问题描述
我有一个标记,当我打开地图就显示了标记。当我点击它,它显示的标题和工具栏,其中包括在这让我发动意图导航到标记或显示在谷歌地图在地图的右下角两个按钮。我想有这种自动显示被打开,而不是让用户点击该标记的地图时。
I have a marker and when I open the map it shows the marker. When I click on it it shows the title and a toolbar which includes two buttons on the bottom right of the map which let me launch intents to navigate to the marker or show it in google maps. I would like to have these displayed automatically when the map is opened rather than having the user to click on the marker.
像这种:-) ... 我似乎无法找出如何做到这一点。
Like this :-) ... I can't seem to work out how to do this.
我曾尝试:
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("title");
// adding marker
googleMap.addMarker(marker).showInfoWindow();
googleMap.getUiSettings().setMapToolbarEnabled(true);
不过,这正说明了标记标题和右上角到我的位置是这两个工具栏按钮的意图在右下角的按钮。
But this just shows the marker title and a button on the top right to go to my location not the two toolbar intent buttons on the bottom right.
像这种:-( ... 我有点卡住任何想法?
Like this :-( ... I'm a bit stuck any ideas?
推荐答案
标记被点击时,创建和销毁在现场含蓄地出现重叠。您不能手动表明,(还)。
The overlay that appears when a marker is clicked, is created and destroyed on-the-spot implicitly. You can't manually show that (yet).
如果你必须有这个功能,你可以在你用2 ImageViews
,并调用相应的意图地图创建叠加时,他们点击:
If you must have this functionality, you can create an overlay over your map with 2 ImageViews
, and call appropriate intents when they're clicked:
// Directions
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?saddr=51.5, 0.125&daddr=51.5, 0.15"));
startActivity(intent);
// Default google map
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?q=loc:51.5, 0.125"));
startActivity(intent);
请注意:你需要基于标记的为getPosition()
和用户的位置来改变坐标
Note: you need to change the coordinates based on Marker's getPosition()
and the user's location.
现在隐藏默认的叠加,所有你需要做的是在 OnMarkerClickListener
返回true。虽然你失去的能力,以显示信息窗口
和中央相机上的标记,你可以模仿,仅仅够了:
Now to hide the default overlay, all you need to do is return true in the OnMarkerClickListener
. Although you loose the ability to show InfoWindows
and center camera on the marker, you can imitate that simply enough:
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
return true;
}
});
这篇关于显示工具栏,谷歌地图标记自动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!