在我的应用程序中,我在地图上绘制路线路径,我在哪里移动并固定源和目的地。所以我使用LocationManager类来获取位置更新myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new myLocationListener());
。我走10米距离没有位置更新完成。所以检查我的代码。我只是将功能放在onStatusChanged函数中(因为它被调用至少一次).i运行应用程序onStatusChanged被调用。我的问题是pin the source and destination and route drawing class called continuously even though the onStatusChanged is not called
。和pin is not pointed and root is not drawn even though their class is called
。
我的代码:
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");
}
}
我的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
等等。 我写的类调用在statuschanged中,但我不知道如果没有状态改变,如何连续调用....如果我错了,请协助我做我的需要。请帮我。
答案 0 :(得分:0)
我认为你需要关注两件事:
1 - 您不应该依赖onStatusChanged来获取最近的位置。
时调用该方法获取最新位置更改的唯一方法是在onLocationChanged。
2 - 叠加层的绘制方法将被称为很多。您不应该依赖该方法来添加标记。您可以在draw方法之外向叠加层添加标记。填充叠加层或使地图无效时,您添加到叠加层的任何标记都将显示在地图上。无需在draw方法中添加标记。
正如您在接受答案Drawing a line/path on Google Maps中所看到的,draw()方法用于绘制2个地理点之间的路径。如果您想在地图上添加标记(图钉),可以在叠加层上执行此操作,有关如何在地图中添加标记的详细信息,请参阅此答案How to clear / reset an ItemizedOverlay in Android?。