本文介绍了当用户停止移动相机的Android谷歌地图V2执行的AsyncTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我提出这是使用谷歌地图API V2的应用程序。我的问题是,当我注册相机更改侦听器,它执行每个摄像头的运动停止时不移动的时间。我要实现后者。如何修改我的code仅移动站时,需要注册?
下面是我的code:
mMap.setOnCameraChangeListener(新GoogleMap.OnCameraChangeListener(){
@覆盖
公共无效onCameraChange(CameraPosition位置){
的LatLngBounds边界= mMap.getProjection()getVisibleRegion()的LatLngBounds。;
NE = bounds.northeast;
SW = bounds.southwest;
NE1 = ne.latitude;
NE2 = ne.longitude;
SW1 = sw.latitude;
SW2 = sw.longitude;
新DownloadJSON()执行();
}
});
解决方案
我实现了自定义计时器都满足的条件,只有当一定时间后执行。这里是我的code:
mMap.setOnCameraChangeListener(新GoogleMap.OnCameraChangeListener(){
@覆盖
公共无效onCameraChange(CameraPosition位置){
的LatLngBounds边界= mMap.getProjection()getVisibleRegion()的LatLngBounds。;
NE = bounds.northeast;
SW = bounds.southwest;
如果(T!= NULL){
t.purge();
t.cancel();
}
T =新的Timer();
t.schedule(新的TimerTask(){
公共无效的run(){
如果(NE1 = ne.latitude和放大器;!&安培;!NE2 = ne.longitude&放大器;&安培; SW1 = sw.latitude和放大器;!&安培;!SW2 = sw.longitude){
NE1 = ne.latitude;
NE2 = ne.longitude;
SW1 = sw.latitude;
SW2 = sw.longitude;
Log.d(变量,刷新数据);
新DownloadJSON()执行();
t.cancel();
}
其他{
NE1 = ne.latitude;
NE2 = ne.longitude;
SW1 = sw.latitude;
SW2 = sw.longitude;}
t.cancel(); //也只是顶部的计时器线程,否则,你可能会收到一个崩溃报告
}
},1000);
//新DownloadJSON()执行();
}
});
I am making an app which is using google maps api v2. My problem is that when I register camera change listener, it executes each time the camera moves not when the moving stops. I want to achieve the latter. How can I modify my code to register only when moving stops ?
Here is my code:
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
ne = bounds.northeast;
sw = bounds.southwest;
ne1 = ne.latitude;
ne2 = ne.longitude;
sw1 = sw.latitude;
sw2 = sw.longitude;
new DownloadJSON().execute();
}
});
解决方案
I implemented custom timer to execute after certain time only when conditions are met. Here is my code:
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
ne = bounds.northeast;
sw = bounds.southwest;
if(t!=null){
t.purge();
t.cancel();
}
t = new Timer();
t.schedule(new TimerTask() {
public void run() {
if(ne1 != ne.latitude && ne2 != ne.longitude && sw1 != sw.latitude && sw2 != sw.longitude){
ne1 = ne.latitude;
ne2 = ne.longitude;
sw1 = sw.latitude;
sw2 = sw.longitude;
Log.d("Tag","Refreshing data");
new DownloadJSON().execute();
t.cancel();
}
else{
ne1 = ne.latitude;
ne2 = ne.longitude;
sw1 = sw.latitude;
sw2 = sw.longitude;}
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
}
}, 1000);
//new DownloadJSON().execute();
}
});
这篇关于当用户停止移动相机的Android谷歌地图V2执行的AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!