我的Android应用程序中有一个 google maps v2 ,上面有一些标记。当用户单击其中一个标记时,会出现标题弹出窗口。如何在没有用户点击的情况下显示这些标题?
答案 0 :(得分:42)
只需致电Marker.showInfoWindow();
即可。请参阅https://developers.google.com/maps/documentation/android/marker#info_windows和https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Marker#showInfoWindow()
答案 1 :(得分:41)
类似的东西:
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Your position")).showInfoWindow();
答案 2 :(得分:12)
你可以这样做:
Marker marker = mMap.addMarker(new MarkerOptions().position(currentPosition).title("Your text"));
marker.showInfoWindow();
答案 3 :(得分:5)
要在标记周围的地图上显示标记标题,我在互联网上找到的所有解决方案都没有对我有用,因此我袖手旁观,制作了这个可以为我解决此问题的库,希望它也可以对其他人有所帮助:< / p>
https://github.com/androidseb/android-google-maps-floating-marker-titles
以下是其工作原理的预览:
答案 4 :(得分:2)
我在某些实现上不太好,但这是我的代码:
public BitmapDescriptor getBitmapFromView(String title) {
View view = LayoutInflater.from(activity.getApplicationContext()).inflate(R.layout.marker_tooltip, null);
((TextView) view.findViewById(R.id.tooltips_title)).setText(title);
//Get the dimensions of the view. In my case they are in a dimen file
int width = activity.getResources().getDimensionPixelSize(R.dimen.tooltips_width);
int height = activity.getResources().getDimensionPixelSize(R.dimen.tooltips_height);
int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
view.measure(measuredWidth, measuredHeight);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return BitmapDescriptorFactory.fromBitmap(bitmap);
}
...
marker.setIcon(getBitmapFromView(marker.getTitle()));
...
我在带有一些变体的地图应用程序的一个片段中实现了这一点。例如,使用自定义信息窗口和地图上的一些事件,但是需要同时执行它才能显示所有标记标题。 让我知道它是否对您也有帮助
“ activity.getResources()。getDimensionPixelSize(R.dimen.tooltips_width)”变量的活动性是片段中的属性
答案 5 :(得分:0)
也许我回答这个问题有点晚了,但是下面的代码对我有用:
//添加此库
public void makersMaker(GoogleMap googleMap){
IconGenerator iconFactory = new IconGenerator(this);
Marker marker1 = googleMap.addMarker(new MarkerOptions().position(newLatLng(-1.3177336,36.8251902));
marker1.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker 1")));
Marker marker2 = googleMap.addMarker(new MarkerOptions().position(new LatLng(-1.2857399,36.8214088)));
marker2.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker 2")));
}
//然后使用下面的方法
Set wbWB = Worksheets("Guidance") '<-- this should be a workbook not a worksheet?
With wbWB '<-- this with is useless until …
If SheetExists("Guidance") Then
Set wsSht = .Sheets("Guidance") '<-- … until Sheets here starts with a dot
wsSht.Copy Before:=sThisWB.Sheets("Guidance") 'if the error is here then there is no sheet "Guidance" in sThisWB
Else
MsgBox ("No worksheet named Guidance")
End If
wbWB.Close SaveChanges:=False
End With