【发布时间】:2012-09-23 15:06:46
【问题描述】:
我不太清楚该程序如何在 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() 的方法,我想在地图上绘制获得的点。我的意图是它像谷歌地图交通层。当我们拖动屏幕或放大/缩小时,我应该连续绘图。为此,我在TouchOverlay 类中的onZoom() 方法中使用了相同的getGPSPoints 方法。
但是当我第一次选择选项和第一次放大/缩小操作时,它只是绘制一次。如果我需要绘制剩余的部分,我必须根据当前的实现再次单击该选项。这项活动如何运作,我应该拥有它?
【问题讨论】:
标签: android android-activity geolocation ip-geolocation