Reputation: 3299
Anyone see why my polyline isn't drawing a line as I move? The map shows up and the position arrow is tracking, but no line is drawn. I thought this was all was needed to continually make the line track:
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);}
}
Upvotes: 0
Views: 1652
Reputation: 7108
I think you continually add a new polyline with only a single point, which gives no line, try and save the rectOptions as a field variable:
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);
}
}
Upvotes: 2