The code works fine first time round, but when locationManager requests a update it doesn't redraw the markers or the polylines when the location changes but the little blue gps circle on it moves by it self and thats it. I want to know how you could get it to change the markers and polylines from the google maps every time the user moves to a new location
public class MyActivity extends FragmentActivity implements RoutingListener {
GoogleMap map;
LatLng User;
LatLng end;
Marker user;
Marker END;
/**
* This activity loads a map and then displays the route and pushpins on it.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
if (map == null) {
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().
findFragmentById(R.id.map);
map = fm.getMap();
if (map != null) {
setUpMap();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void setUpMap() {
map.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 5000, 0, (android.location.LocationListener) this);
if(locationManager!=true){
onLocationChanged(myLocation);
}
}
private void onLocationChanged(Location myLocation) {
user.remove();
END.remove();
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
end = new LatLng(51.493873, -3.18175);
User = new LatLng(latitude, longitude);
Marker user = map.addMarker(new MarkerOptions().
position(new LatLng(latitude, longitude)).title("you").icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue)));
Marker END = map.addMarker(new MarkerOptions().
position(end).title("Other User").icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green)));
map.moveCamera((CameraUpdateFactory.newLatLng(User)));
map.animateCamera(CameraUpdateFactory.zoomTo(15));
Routing routing = new Routing(Routing.TravelMode.WALKING);
routing.registerListener(this);
routing.execute(User,end);
}
@Override
public void onRoutingFailure() {
// The Routing request failed
}
@Override
public void onRoutingStart() {
// The Routing Request starts
}
@Override
public void onRoutingSuccess(PolylineOptions mPolyOptions, Route route) {
PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(Color.BLUE);
polyOptions.width(10);
polyOptions.addAll(mPolyOptions.getPoints());
map.addPolyline(polyOptions);
}
}