2013-09-25 78 views
0

任何人都可以看到爲什麼我的多段線在移動時沒有畫線?地圖顯示並且位置箭頭正在跟蹤,但不繪製線。我認爲這一切都是需要不斷進行線軌道:Polyline沒有在Api v2上顯示android

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


} 

回答

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


     } 
相關問題