bladi
bladi

Reputation: 13

how to get the coordinates of a draggable marker andorid?

Good afternoon I am implementing a map, you can enter my position of a marker, but how can I get the new latitude and longitude of the marker when moving to another position

Upvotes: 1

Views: 302

Answers (1)

zhangxaochen
zhangxaochen

Reputation: 34017

Your question is how to obtain the new longitude and latitude of a marker after it is dragged to a new position.

HUAWEI Map Kit provides the HuaweiMap.OnMarkerDragListener() API to listen for marker drag events. For details about this API, please visit HuaweiMap.OnMarkerDragListener.

You can override the onMarkerDragStart, onMarkerDrag, and onMarkerDragEnd methods in the API to obtain the marker information under different drag status.

The sample code is as follows:

hMap.setOnMarkerDragListener(new HuaweiMap.OnMarkerDragListener() {
    @Override
    public void onMarkerDragStart(Marker marker) {
        Log.i(TAG, "start drag");
        // your code
    }

    @Override
    public void onMarkerDrag(Marker marker) {
        Log.i(TAG, "drag");
// your code
    }

    @Override
    public void onMarkerDragEnd(Marker marker) {
// your code
        Log.i(TAG, "end drag");
        Log.i(TAG, marker.getPosition().toString());

Upvotes: 1

Related Questions