Issue
I have two points on the map:
- User location (which gets redrawn every time new coordinates are received)
- Pickable location which user can pick hem self (by taping on the map). If new point is picked, immidently deletes the old one.
Problem:
When user picks a location Overlay.onTap(GeoPoint p, MapView mapView)
is activated. MapView.getOverlays() receives all the items on the map. I need to delete the old marker on the map, but there is no way to make the difference which overlay object is the old user picked location and which one is the user current location icon.
Question:
Would be it anyway possible to manage multiple layers of Overlay objects on MapView?
Solution
you can create the Multiple sub class with implement the Overlay. Now current location was fixed and i think on that you can't do any event like onclick or etc. 1 class which only display and maintain only current location.
So now for the pick location. ok I think you want to change the location of the location of that pin. As you can onTap implement for that you can use the onTouch() method and implement the down, move, up event for the map suppose if I tap on the map then you get that location now convert this location value into the screen x,y value add pass to the pin to place on that place.
here i have implement like this way for place the pin on map when user tap on map
public boolean onTouchEvent(MotionEvent event, final MapView mapView) {
final int action=event.getAction();
final int x=(int)event.getX();
final int y=(int)event.getY();
result = false;
if (action==MotionEvent.ACTION_DOWN) {
downPressed = true;
drag = false;
result = false;
}else if (action==MotionEvent.ACTION_MOVE) {
downPressed = false;
drag=true;
}else if (action==MotionEvent.ACTION_UP) {
if(downPressed){
if(task.equals(SINGLE_LOCATION) | isDirectionPoint | mapView.isStreetView()){
tempPoint = mapView.getProjection().fromPixels(x, y);
mapView.invalidate();
}
}
drag = false;
downPressed = false;
}
return(result | super.onTouchEvent(event, mapView));
}
here is my draw method which was call in draw() method
private void drawFreeMarker(Canvas canvas, MapView mapView, boolean shadow) {
Point screenPts = new Point();
mapView.getProjection().toPixels(tempPoint, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bluepin_38);
canvas.drawBitmap(bmp, screenPts.x-((xCurLocOffset/2)-1), screenPts.y-(yCurLocOffset-1), null);
}
Answered By - Pratik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.