Polyline没有出现在Api v2 android上

时间:2013-09-25 21:06:26

标签: java android google-maps google-maps-android-api-2

任何人都明白为什么我的折线在移动时没有划线?地图显示并且位置箭头正在跟踪,但没有绘制线条。我认为这一切都需要不断进行线路跟踪:

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);}


}   

1 个答案:

答案 0 :(得分: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);
             }


        }