我不太清楚该程序如何在 Android 中运行。过去两个月我开始在 Android 上工作,而且我还是 Java 的初学者。所以,我正在尽我所能去发展和学习。这是我实现的一段代码,我不太清楚它是如何按照我的要求工作的。
activity{
onCreate(){
/* here i am using google maps api and trying to plot the current location*/
OverlayItem overlayItem1 = new OverlayItem(ourLocation,"Our Location","Position");
CustomPinpoint custom1 = new CustomPinpoint(d, Activity.this);
custom1.insertPinpoint(overlayItem1);
overlayList.add(custom1);
controller.animateTo(ourLocation);
}
private class TouchOverlay extends com.google.android.maps.Overlay{
public boolean onTouchEvent(MotionEvent event, MapView map){
onZoom();
}
}
public boolean onCreateOptionsMenu(Menu menu){}
public boolean onOptionsItemSelected(MenuItem item){
case.X:
getGPSPoints();//Here i will be getting some gps points from stored database
// and I would like to plot them all on the map.
TouchOverlay touchOverlay = new TouchOverlay();
overlayList.add(touchOverlay);
}
onPause(){
super.onPause();
lm.removeUpdates(this);
}
onResume(){
super.onResume();
lm.requestLocationUpdates(towers, 500, (float) 0.5, this);
}
onLocationChanged(Location l) {
// TODO Auto-generated method stub
clearmap();
lat = (int) (l.getLatitude()*1E6);
longi = (int) (l.getLongitude()*1E6);
GeoPoint ourLocation = new GeoPoint(lat, longi);
CustomPinpoint custom = new CustomPinpoint(d, TrafficMapActivity.this);
OverlayItem overlayItem = new OverlayItem(ourLocation,"Our location","Position");
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
}
}
我的问题是何时onLocationChanged
调用方法以及 onTouchEvent 方法?
我创建了一个方法getGPSPoints()
,我想在地图上绘制获得的点。我的意图是它像谷歌地图交通层。当我们拖动屏幕或放大/缩小时,我应该连续绘图。为此,我在类的方法中使用相同的getGPSPoints
方法。onZoom()
TouchOverlay
但是当我第一次选择该选项并进行第一次放大/缩小操作时,它只是绘制一次。如果我需要绘制剩余的部分,我必须根据当前的实现再次单击该选项。这项活动如何运作,我应该拥有它?