2016-04-04 11 views
1

GoogleマップAPIを使用してアプリを作成しています。このアプリはユーザーのステップをGoogleマップに描画します。私はリアルタイムでユーザーの歩みを描くことに成功しました。 ボタンを使用して描画線を停止します。したがって、onClickListenerのinsultメソッド。 これは私のコードがGoogleマップ(Android)でポリラインを削除したい

private GoogleMap map; 
    private PolylineOptions polylineOptions; 
    private Polyline polyline; 

    private LocationManager locationManager; 
    private myLocation mylocation = new myLocation(); 

    private Button btn_clear, btn_start; 

    private ArrayList<LatLng> testArray = new ArrayList<LatLng>(); 


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

     btn_start = (Button) findViewById(R.id.btn_start); 
     btn_start.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
       locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
       locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,mylocation); 
       return; 
      } 
     }); 
     btn_clear = (Button) findViewById(R.id.btn_clear); 
     btn_clear.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       polyline.remove(); 
       map.clear(); 
       locationManager.removeUpdates(mylocation); 
       Intent intent = new Intent(TEST.this, WalkResult.class); 
       startActivity(intent); 

      } 
     }); 
     polylineOptions = new PolylineOptions(); 
    } 

    public class myLocation implements LocationListener { 

     @Override 
     public void onLocationChanged(Location location) { 
      LatLng spot = new LatLng(location.getLatitude(), location.getLongitude()); 

      testArray.add(spot); 

      polyline = map.addPolyline(polylineOptions 
      .add(testArray.get(0)) 
      .color(Color.DKGRAY)); 

      Log.d("Insult", "testArray : " + testArray.get(0)); 
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(spot, 17)); 
      map.addPolyline(polylineOptions); 

      testArray.remove(0); 
     } 

で、Polyline.removeは、行を削除しないです。ポリラインがなぜ消えないのか分かりません。 理由を見つけるために、 'LocationListener'に 'polyline.getPoints'を使用します。これが結果です。

04-04 10:10:48.885 10661-10661/kr.co.wdream D/Removing?: polyline : [lat/lng: (37.4851513,126.8986154)] 
04-04 10:10:57.695 10661-10661/kr.co.wdream D/Removing?: polyline : [lat/lng: (37.4851513,126.8986154), lat/lng: (37.4851387,126.8985779)] 

04-04 10:11:30.325 10661-10661/kr.co.wdream D/Removing?: polyline : [lat/lng: (37.4851513,126.8986154), lat/lng: (37.4851387,126.8985779), lat/lng: (37.4851357,126.8985547), lat/lng: (37.4851495,126.8986224)] 

それが正しいですか? どうすればいいですか?お願い助けて。

答えて

0

まあ、私はこの問題を解決します。私はこれが良い答えだとは思わないが、それは仕事だ。 'startActivity'の後に 'finish()'メソッドを使用します。そして、このアクティビティ(マップアクティビティ)を返すときは、startActivityを使用してアクティビティを再開します。 すべてのポリラインのポイントが削除されました。ありがとうございました

関連する問題