【问题标题】:Map Marker with Muliline Info Window带有 Muliline 信息窗口的地图标记
【发布时间】:2017-09-16 06:48:33
【问题描述】:

以下代码中的文本未完全显示在信息窗口中(如下所示):

mMap.addMarker(new MarkerOptions().position(the_local_user2).title("My Title").snippet("My Snippet"+"\n"+"1st Line Text"+"\n"+"2nd Line Text"+"\n"+"3rd Line Text")
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

我希望它看起来像这样:

找到了Marker-Plugins SDK,不知道好不好。

如何让信息窗口显示多行文本?

【问题讨论】:

    标签: java google-maps android-studio marker


    【解决方案1】:

    您可以使用多行文本创建custom info window

    为此,您只需在您的Activity 中实现GoogleMap.InfoWindowAdapter 并为信息窗口添加一个自定义View。然后拨打GoogleMap#setInfoWindowAdapter

    public class MapActivity extends AppCompatActivity imeplements OnMapReadyCallback, GoogleMap.InfoWindowAdapter {
    
        private GoogleMap mGoogleMap;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstaceState);
            setContentView(r.layout.activity_map);
    
            SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            fragment.getMapAsync(this);
        }
    
        @Override
        public void onMapReady(GoogleMap googleMap) {
            googleMap.setInfoWindowAdapter(this);
            mGoogleMap = googleMap;
        }
    
        @Override
        public View getInfoWindow(Marker marker) {
            return null; // Use default info window background
        }
    
        @Override
        public View getInfoContents(Marker marker) {
            View view = getLayoutInflater().inflate(R.layout.info_window_multiline, null);
    
            TextView titleTextView = (TextView) view.findViewById(R.id.title);
            TextView snippetTextView = (TextView) view.findViewById(R.id.snippet);
    
            titleTextView.setText(marker.getTitle());
            snippetTextView.setText(marker.getSnippet());
    
            return view;
        }
    
    }
    

    另外,Cordova GoogleMaps Plugin 适用于使用CordovaPhoneGap 开发框架的应用程序;不适用于原生 Android 开发。 Google Maps Android API 用于原生开发;您似乎已经在使用它。不要混淆两者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 2011-02-24
      • 1970-01-01
      相关资源
      最近更新 更多