in my app i am drawing route path on map where ever i am moving and pin the source and destination. so i use LocationManager class for get location update as itmyManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new myLocationListener());. i go 10 meter distance no location update is done. so for the checking my code. i just put functionality in the onStatusChanged function(because it is called at least one time).i run the app onStatusChanged is called. what my problem is pin the source and destination and route drawing class called continuously even though the onStatusChanged is not called. and pin is not pointed and root is not drawn even though their class is called.
my code:
public class Map extends MapActivity
{
// class for pin the location
class MapOverlay extends com.google.android.maps.Overlay
{
............
Log.e("loc","true");
}
public void onCreate(Bundle savedInstanceState)
{
..................
myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new myLocationListener());
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
class myLocationListener implements LocationListener {
public void onLocationChanged(Location loc) {
}
........
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.e("MAP","onStatusChanged - called");
....// finding lat and lng getting.
Log.e("Updated Location",""+latPointDst+" , "+lngPointDst);
..........
// here i called MyOverlay class -- root drawing.
// here i called MapOverlay class -- pin the location
}
}
public class MyOverlay extends Overlay {
.............
Log.e("location change","drawing");
}
}
my logcat:
05-30 13:29:54.653: ERROR/MAP(3850): onStatusChanged - called
05-30 13:29:54.673: ERROR/Updated Location(3850): 9.909228086471558 , 78.10081958770752
05-30 13:29:54.743: ERROR/loc(3850): true
05-30 13:29:54.783: ERROR/loc(3850): true
05-30 13:29:54.793: ERROR/loc(3850): true
05-30 13:29:54.803: ERROR/loc(3850): true
05-30 13:29:54.813: ERROR/location change(3850): drawing
05-30 13:29:54.983: ERROR/loc(3850): true
05-30 13:29:54.993: ERROR/loc(3850): true
05-30 13:29:54.993: ERROR/loc(3850): true
05-30 13:29:55.003: ERROR/loc(3850): true
05-30 13:29:55.013: ERROR/location change(3850): drawing
05-30 13:29:55.193: ERROR/loc(3850): true
05-30 13:29:55.203: ERROR/loc(3850): true
05-30 13:29:55.223: ERROR/loc(3850): true
05-30 13:29:55.233: ERROR/loc(3850): true
05-30 13:29:55.243: ERROR/location change(3850): drawing
05-30 13:29:55.473: ERROR/loc(3850): true
05-30 13:29:55.483: ERROR/loc(3850): true
05-30 13:29:55.573: ERROR/loc(3850): true
05-30 13:29:55.603: ERROR/loc(3850): true
05-30 13:29:55.633: ERROR/location change(3850): drawing
05-30 13:29:55.693: ERROR/loc(3850): true
and so on.
i write class calling within on statuschanged but i do not know how is called continuously without on status changed.. . if i am wrong please assist to do my need. please help me.
I think you need to focus on 2 things here :
1 – You shouldn’t rely on the onStatusChanged to get a recent location. The method is called when
The only way to get up to date location changes is in onLocationChanged.
2 – The draw method of the overlay will be called a lot. You shouldn’t rely on that method to add markers. You can add markers to your overlay outside the draw method. When you populate the overlay, or invalidate the map, any markers that you added to the overlay will be shown on the map. No need to add the markers in the draw method.
As you can see from the accepted answer here Drawing a line/path on Google Maps, the draw() method is used to draw a path between 2 geopoints. If you want to add markers (pins) to the map, you can do it on your overlay, see this answer How to clear / reset an ItemizedOverlay in Android? for more info on how to add markers to the map.