0

My MapActivity records a polyline just fine however when I tip the screen on it's side and the orientation changes the polyline disappears? What could be causing this? Here is my code that is recording the polyline:

Location lastLocationloc;
private GoogleMap myMap;
@Override
public void onLocationChanged(Location location) {
    if (lastLocationloc == null) { 
         lastLocationloc = location;
     }
     LatLng lastLatLng = locationToLatLng(lastLocationloc);
     LatLng thisLatLng = locationToLatLng(location);
     //Log.e(TAG, "Last LatLng is :"+lastLatLng);
     //Log.e(TAG, "Last LatLng is :"+thisLatLng);
     myMap.addPolyline(new PolylineOptions().add(lastLatLng).add(thisLatLng).width(10).color(Color.RED));
     lastLocationloc = location;
}

How can I prevent this from happening?

user268397
  • 1,917
  • 7
  • 38
  • 56

1 Answers1

0

You have to save your points and restore them later. One simple way is to use onSaveInstanceState which will keep your data across configuration changes and process being killed. Other options are files and DB. More info here: http://developer.android.com/guide/topics/data/data-storage.html

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94