onLocationChanged 不会自动调用
我在 Android 中遇到 onLocationChanged 事件的问题。这是触发:
case R.id.start: {
Points.add(overlay.getMyLocation()); // Points' type is ArrayList<GeoPoint>
mgr.requestLocationUpdates(best, 0, 3, locationListener);
}
break;
这是 onLocationChanged 方法:
public void onLocationChanged(Location location) {
i++;
Points.add(overlay.getMyLocation());
MapOverlay mapOverlay = new MapOverlay(Points.get(i-1), Points.get(i));
map.getOverlays().add(mapOverlay); //does the drawing
mMapController.animateTo(Points.get(i));
}
因此, onLocationChanged 仅被调用一次,并且仅在我按“开始”后。每次位置改变时它都会自动调用,对吗?就我而言,事实并非如此。
请帮我。
I have a problem with onLocationChanged event in Android. Here's the triggering:
case R.id.start: {
Points.add(overlay.getMyLocation()); // Points' type is ArrayList<GeoPoint>
mgr.requestLocationUpdates(best, 0, 3, locationListener);
}
break;
And here's the onLocationChanged method:
public void onLocationChanged(Location location) {
i++;
Points.add(overlay.getMyLocation());
MapOverlay mapOverlay = new MapOverlay(Points.get(i-1), Points.get(i));
map.getOverlays().add(mapOverlay); //does the drawing
mMapController.animateTo(Points.get(i));
}
So, onLocationChanged is called only once and only after I press "start". It's supposed to be called automatically every time the location has changed, right? In my case, it's not.
Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎解决了。
在 onCreate 中,我添加了:
onLocationChanged 现在看起来像这样:
另外,非常重要的方法:
还有一些新的权限:
Problem seems to be solved.
In onCreate, I added:
onLocationChanged now looks like that:
Also, very important methods:
And also some new permissions: