2017-08-11 111 views
0

我正在使用Google地图Android API的Android应用程序。我在地图上显示多个标记,并且想要在每个标记旁边显示一个标签,如下图所示,但我无法找出如何去做吧。如何在Android上的Google地图上的标记旁边显示标签?

Image with google map marker and label

我已经通过谷歌地图文档了在https://developers.google.com/maps/documentation/android-api/map-with-marker 但我无法找到如何显示在这个manner.I标签细节都试图开辟了一个弹出,但我title属性需要一个展示我的标记的详细视图(信息窗口),我需要显示的主标题,而无需打开弹出任何标记

任何想法,我怎么能以这样的方式添加标记在附加的图像显示?

+1

您可以检查这些https://stackoverflow.com/questions/17989389/label-at -The-top-of-the-marker-in-google-maps-api-v2 –

+0

@NavjotSingh:我已经看到了这些。标题属性仅在用户点击标记时显示 –

回答

1

不知道这是你脑子里想的是什么,但在这里不用

创建MarkerOptions对象:

MarkerOptions options = new MarkerOptions() 
       .title(name) 
       .position(source) 
       .icon(gettIconFromDrawable(myMarker)) 
       .snippet("Briefly describe \nyour content here"); 

然后标记添加到地图

Marker sourceMarker = mMap.addMarker(options); 

创建InfoWindowAdapter以容纳摘录中的多行。 (原来这里的answer

mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 

      @Override 
      public View getInfoWindow(Marker arg0) { 
       return null; 
      } 

      @Override 
      public View getInfoContents(Marker marker) { 

       Context context = getApplicationContext(); //or getActivity(), YourActivity.this, etc. 

       LinearLayout info = new LinearLayout(context); 
       info.setOrientation(LinearLayout.VERTICAL); 

       TextView title = new TextView(context); 
       title.setTextColor(Color.BLACK); 
       title.setGravity(Gravity.CENTER); 
       title.setTypeface(null, Typeface.BOLD); 
       title.setText(marker.getTitle()); 

       TextView snippet = new TextView(context); 
       snippet.setTextColor(Color.GRAY); 
       snippet.setText(marker.getSnippet()); 

       info.addView(title); 
       info.addView(snippet); 

       return info; 
      } 
     }); 

最后,添加该属性,以保证标记保持可见

sourceMarker.showInfoWindow(); 
+0

感谢您的帮助。但实际上,我在问题中提到我已经使用infoWindow来显示有关标记对象的自定义和详细的视图。我需要为地图上的所有标记显示一行标记,而不点击标记 –

+0

这就是'sourceMarker.showInfoWindow();'应该做什么 –

+0

但我的要求稍有不同。所有标记都必须有可见的标签,并且点击标记时应该显示具有该标记详细信息的详细信息窗口 –

相关问题