I have to make an application with a marker on the center of a srceen and by moving the map and not the marker get lat,lon of the point that the marker shows. I have search the internet for something like Drag Marker but I am not sure if this is what I need.Any Solution?
Asked
Active
Viewed 201 times
0
-
YOu could listen to map movments and recalculate the markers position – Mirco Feb 09 '13 at 23:47
-
In android its quite difficult to listen map change. Android have touchListeners only. Try searching for draw circle on map centre. I did something similar. But my point follow the mapcentre with some delay. If your intrested in my code please let me know in that case. – Fahad Ishaque Feb 10 '13 at 08:08
1 Answers
0
In your mapActivity wrtie this.
Location l = new Location();
// Location class will be used to calculate distance moved by map
TimerTask tm;
GeoPoint oldCenterOfMap, newCenteOfMap;
// On your on resume method of activity do 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;
}
Previous code would keep the track of the map movement. Next code will respond in case of map movement. In the comments present in the code above ( // here is what you do after you touched a map moved after 1.2 seconds AND // Here is what would you do when you lift your finger fromt he map*****) follow the instruction on my answer on another post. Here Adding multiple overlays on mapview dynamically
Edit
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;
}
Here is the function (CalclauteDistance) from location class.

Community
- 1
- 1

Fahad Ishaque
- 1,916
- 1
- 17
- 21
-
Thanks for sending me the code but I have a problem.At the point"l.CalclauteDistance"it tells me that is undefined for the type location.Should i change this method with an other? – Dimitris Feb 13 '13 at 15:30
-
you can use distanceTo or any other method avaliable in your API to calculate distance between two point. But please make sure the data type it returns. 10-hours from now, i'll update you with this methode also. – Fahad Ishaque Feb 13 '13 at 19:06
-