Zeigt mein track mit Google Maps api v2 in android

Ich versuche, eine app, die Ihnen zeigen, meine aktuelle Position und verfolgt mich von dort mit einer Linie.Ich habe mit Google maps Api v2 für android, so versuchte ich, zu arbeiten mit Polylinien, mir zu helfen, zeigen meine tracks aber seine nicht angezeigt.
Kann mir jemand helfen mit, dass..Danke.
Gesamt-code wird zur Verfügung gestellt.

public class MainActivity extends FragmentActivity implements ConnectionCallbacks,
    OnConnectionFailedListener, LocationListener,
    OnMyLocationButtonClickListener, OnClickListener, android.location.LocationListener {

private GoogleMap mMap;

private LocationClient mLocationClient;
private TextView mMessageView;
private boolean setIt;


//These settings are the same as the settings for the map. They will in fact give you updates
//at the maximal rates currently possible.
private static final LocationRequest REQUEST = LocationRequest.create()
        .setInterval(5000)         //5 seconds
        .setFastestInterval(16)    //16ms = 60fps
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_location_demo);
    mMessageView = (TextView) findViewById(R.id.message_text);
    Button b1=(Button)findViewById(R.id.start);
    Button b2=(Button)findViewById(R.id.stop);
    b1.setOnClickListener(this);
    b2.setOnClickListener(this);
}


@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
    setUpLocationClientIfNeeded();
    mLocationClient.connect();

}

@Override
public void onPause() {
    super.onPause();
    if (mLocationClient != null) {
        mLocationClient.disconnect();
    }
}

private void setUpMapIfNeeded() {
    //Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        //Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        //Check if we were successful in obtaining the map.
        if (mMap != null) {
            mMap.setMyLocationEnabled(true);
            mMap.setOnMyLocationButtonClickListener(this);
        }
    }
}

private void setUpLocationClientIfNeeded() {
    if (mLocationClient == null) {
        mLocationClient = new LocationClient(
                getApplicationContext(),
                this,  //ConnectionCallbacks
                this); //OnConnectionFailedListener
    }
}

/**
 * Button to get current Location. This demonstrates how to get the current Location as required
 * without needing to register a LocationListener.
 */
public void showMyLocation(View view) {
    if (mLocationClient != null && mLocationClient.isConnected()) {
        String msg = "Location = " + mLocationClient.getLastLocation();
        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }
}


@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.start) {
            setIt = true;
            };
        if (v.getId() == R.id.stop) {
            mMap.clear();
            };


}

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

@Override
public void onLocationChanged(Location location) {
    mMessageView.setText("Location = " + location);


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

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



@Override
public void onConnected(Bundle connectionHint) {
    mLocationClient.requestLocationUpdates(
            REQUEST,
            this);  //LocationListener
}

/**
 * Callback called when disconnected from GCore. Implementation of {@link ConnectionCallbacks}.
 */
@Override
public void onDisconnected() {
    //Do nothing
}

/**
 * Implementation of {@link OnConnectionFailedListener}.
 */
@Override
public void onConnectionFailed(ConnectionResult result) {
    //Do nothing
}

@Override
public boolean onMyLocationButtonClick() {

    {
        setIt = true;
        };
    Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
    //Return false so that we don't consume the event and the default behavior still occurs
    //(the camera animates to the user's current position).
    return false;


}

@Override
public void onProviderDisabled(String arg0) {
    //TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String arg0) {
    //TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
    //TODO Auto-generated method stub

}
}
Wo stellen Sie setIt zu wahren?
Ich setzte Sie auf die Schaltfläche start klicken und auf die Schaltfläche weiter .
Ist onLocationChanged aufgerufen wird, erfolgreich?

InformationsquelleAutor user3160651 | 2014-01-06

Schreibe einen Kommentar