0

我必须在屏幕中心创建一个带有标记的应用程序,并通过移动地图而不是标记获得标记显示点的纬度、经度。我已经在互联网上搜索了 Drag Marker 之类的东西,但我不确定这是否是我需要的。任何解决方案?

4

1 回答 1

0

在你的 mapActivity 中写这个。

Location l = new Location();
// Location class will be used to calculate distance moved by map
TimerTask tm;
GeoPoint oldCenterOfMap, newCenteOfMap;

// 在你的 on resume 方法上做 oldCenterOfMap = mapView.getMapCenter();

Handler mHandler = new Handler();
int isTouched = 0;
MapView mapview = (MapView) findViewById(R.id.yourmapview_from_xml);

mapView.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {

if (event.getAction() == MotionEvent.ACTION_UP) {
newCenteOfMap = mapView.getMapCenter();

if (mapchanged(oldCenterOfMap, newCenteOfMap)) {
isTouched++;

    // Here is what would you do when you lift your finger fromt he map*****
newCenteOfMap =mapView.getMapCenter());

if (isTouched >= 1) {
if (isTouched > 1) {
mHandler.removeCallbacks(tm_circle);
isTouched = 1;
}
mHandler.postDelayed(tm_circle, 1200);
}
}
if (!mapchanged(oldCenterOfMap, newCenteOfMap))
mHandler.removeCallbacks(tm_circle);
}

return false;
}
});


tm_circle = new TimerTask() {

@Override
public void run() {
isTouched = 0;
// here is what you do after you touched a map moved after 1.2 seconds
oldCenterOfMap = mapView.getMapCenter();

}
};


public boolean mapchanged(GeoPoint oldCenter, GeoPoint newCenter) {

    String distance = l.CalclauteDistance(oldCenter.getLongitudeE6() / 1E6,
            oldCenter.getLatitudeE6() / 1E6,
            newCenter.getLongitudeE6() / 1E6,
            newCenter.getLatitudeE6() / 1E6);

    if (Double.valueOf(distance) == 0.0)
        return false;
    else
        return true;
}

以前的代码会跟踪地图的移动。下一个代码将在地图移动的情况下做出响应。在上面代码中的注释中(//这是您在触摸 1.2 秒后移动的地图后执行的操作和//这是当您从地图上抬起手指时您会执行的操作*****)遵循关于我在另一篇文章中的回答的说明。在地图视图上动态添加多个叠加层

编辑

public String CalclauteDistance(double long1, double lat1, double long2,
        double lat2) {
    String Result;
    Point p1 = new Point(long1, lat1);
    Point p2 = new Point(long2, lat2);
    Result = p1.distanceTo(p2) + "";
    return Result;

}

这是来自位置类的函数(CalclauteDistance)。

于 2013-02-12T07:47:12.057 回答