.snippet中的多行或折线(google maps apiv2)

KS *_*Tan 10 google-maps infowindow google-maps-api-2 google-maps-android-api-2

我正在开发谷歌地图APIv2.我现在面临的问题是我只能在info windows/snippet中添加一行单词.但是我想要的输出能够以断线形式显示,如下图所示.那么有什么可能的方法来解决它吗?

例:

坐标:03.05085,101.70506

限速:80公里/小时

public class MainActivity extends FragmentActivity {
  static final LatLng SgBesi = new LatLng(03.05085, 101.76022);
  static final LatLng JB = new LatLng(1.48322, 103.69065);
  private GoogleMap map;


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
            .getMap();

    map.addMarker(new MarkerOptions().position(SgBesi)
        .title("KM D7.7 Sungai Besi")               //name
        .snippet("Coordinate: 03.05085, 101.70506"));   //description

    map.addMarker(new MarkerOptions().position(JB)
        .title("test") 
        .snippet("Hey, how are you?")); 

       // .icon(BitmapDescriptorFactory  //set icon
       //     .fromResource(R.drawable.ic_launcher)));

    // move the camera instantly with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(SgBesi, 15));

    // zoom in, animating the camera.       
    map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
   }
}
Run Code Online (Sandbox Code Playgroud)

ton*_*y m 21

您需要使用自定义InfoWindowAdapter将布局更改为InfoWindow使用布局文件定义的自定义设计.基本上你需要:

  1. 使用声明你的功能 GoogleMap.setInfoWindowAdapter(Yourcustominfowindowadpater)
  2. 有一个类如下:

...

class Yourcustominfowindowadpater implements InfoWindowAdapter {
    private final View mymarkerview;

    Yourcustominfowindowadpater() {
        mymarkerview = getLayoutInflater()
            .inflate(R.layout.custominfowindow, null); 
    }

    public View getInfoWindow(Marker marker) {      
        render(marker, mymarkerview);
        return mymarkerview;
    }

    public View getInfoContents(Marker marker) {
       return null;
    }

    private void render(Marker marker, View view) {
       // Add the code to set the required values 
       // for each element in your custominfowindow layout file
    }
}
Run Code Online (Sandbox Code Playgroud)


Mac*_*ski 0

您必须使用 InfoWindowAdapter 来创建自定义信息窗口。默认实现以某种方式从代码片段中删除换行符,这可能被认为是一个小错误。