0

任何人都知道为什么我的折线在我移动时没有画线?地图显示并且位置箭头正在跟踪,但没有画线。我认为这就是不断制作线路所需的全部内容:

PolylineOptions rectOptions = new PolylineOptions()
.add(new LatLng(location.getLatitude(), location.getLongitude()));
rectOptions.color(Color.RED);
mMap.addPolyline(rectOptions);


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    LocationManager locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);


    locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

        if (v.getId() == R.id.button1) {setIt = true;};
        if (v.getId() == R.id.button2) { mMap.clear();};
        if (v.getId() == R.id.buttonPauseIt) { setIt = false;};
        if (v.getId() == R.id.buttonResume) { setIt = true;};

}

@Override
public void onLocationChanged(Location location) {


    PolylineOptions rectOptions = new PolylineOptions()
    .add(new LatLng(location.getLatitude(), location.getLongitude()));
    rectOptions.color(Color.RED);

     if (setIt == true){
          mMap.addPolyline(rectOptions);}


}   
4

1 回答 1

2

我认为您不断添加一条只有一个点的新折线,它没有给出线,尝试将 rectOptions 保存为字段变量:

        PolylineOptions rectOptions = new PolylineOptions().width(3).color(
                Color.RED);

        @Override
        public void onLocationChanged(Location location) {


            rectOptions.add(new LatLng(location.getLatitude(), location.getLongitude()));

             if (setIt == true){
                  mMap.addPolyline(rectOptions);
             }


        }  
于 2013-09-25T22:19:06.953 回答