Mapbox Android SDK - Draggable marker -


How to drag a marker? Is this also possible?

If not, does other free open map engines support this feature?

Thank you!

I had to implement draggable markers for one of my projects I found that the only solution was drag drag event For extension of existing marker class with Mehod's investigation and updating marker status accordingly.

  package com.example.map; Import android.graphics.PointF; Import android.graphics.Rect; Import android.graphics.RectF; Import android.util.log; Import android.view.MotionEvent; Import android.view.View; Import com.mapbox.mapboxsdk.api.ilatLng; Import com.mapbox.mapboxsdk.geometry.LatLng; Import com.mapbox.mapboxsdk.overlay.Marker; Import com.mapbox.mapboxsdk.views.MapView; Import com.mapbox.mapboxsdk.views.util.Projection; Public Square DraggableMarker Marker {Private Static Final String Tag = "map.DraggableMarker" provides; Private boolean mIsDragged; Private static last rectf mTempRect = new RectF (); Private stationary final point MTMPpoint = new point (); Personal Float MDX, MDI; Public dragbble marker (string title, string description, wave long latte) {super (title, description, lattel); MIsDragged = false; } Public Dragabal Marker (Map Viv MV, String Attitle, String Adecision, Lat Long ALLNG) {Super (MV, Atital, Edecson, ALTLNG); MIsDragged = false; } Public Boolean Drag (see V, Motion Event Event) {Final Interaction Action = Event. Gate action mascade (); If (action == MotionEvent.ACTION_DOWN) {projection PJ = ((Mapview) v) .getProjection (); RectF binding = received drawings bones (PJ, amtamprect); If (bound context (event.getX (), event.getY ())) {mIsDragged = true; Point P = getPositionOnScreen (PJ, MTP); MDx = p.x - event.getX (); Mdy = p.y - event.getY (); }} If (mIsDragged) {if ((action == MotionEvent.ACTION_CANCEL) || (action == MotionEvent.ACTION_UP)) {mIsDragged = false; } And {projection PG = ((Map V) v) .getProjection (); Illlang Pausz = PJ. From Pixel (event.getX () + MDX, Event .getY () + MD); Setpoint (new wave long (paused metadite ()), pause legacy ()); }} Returned MIS drug; }}  

Later you need to add the listener to the touch event on the map view and check whether your marker (or one of the many from your marker collection) is affected by the event.

mMarker = New Dragabell marker (mMapView, "", "", acenter); MMarker.setIcon (getActivity (). GetApplicationContext (), icon size, mall, "marker-stroke", "FF0000")); MMapView.addMarker (mMarker); MMapView.setOnTouchListener (see new OnTouchListener) {@ Override Public Boolean On Touch (see V, Motion Event Event) {return MM marker.Drag (V, Event);}});

Comments

  1. i implement your class DragabellMarker class but i am facing an issue is that
    these four imports does not exist
    import com.mapbox.mapboxsdk.api.ILatLng;
    import com.mapbox.mapboxsdk.overlay.Marker;
    import com.mapbox.mapboxsdk.views.MapView;
    import com.mapbox.mapboxsdk.views.util.Projection;

    i also import depencies in gradle file but these not recognize meas overlay,api,views
    help me so i solve it
    or give me your gradle depences relataed top mapbox

    ReplyDelete

Post a Comment

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -