通过稳定的市场获得纬度,经度?

时间:2013-02-09 23:38:36

标签: android google-maps gis

我必须使用标记在srceen的中心并移动地图 而不是标记得到lat,标记显示的点的lon。我在互联网上搜索像Drag Marker这样的东西,但我是 不确定这是否是我需要的。任何解决方案?

1 个答案:

答案 0 :(得分:0)

在mapActivity中使用此功能。

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

//在你的简历活动方法上做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秒之后触摸地图后所做的事情和//这是当你从地图上抬起手指时你会做什么*****)跟随关于我在另一篇文章中回答的说明。 这里Adding multiple overlays on mapview dynamically

编辑

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)。