Topic: Get new Lat/Lng after marker drag

Hello,

I'm trying to allow the user to edit their location that is created by the OnlineMapsLocationService.  If the user thinks the marker should be in a different spot they can long press then drag the marker.

Everything is working except when trying to get the new lat/lng OnMarkerRelease, it always shows the same coordinates no matter how far away I drag the marker.  Any help on getting the new lat/lng after dragging the marker would be great.  My code is below.

public class GetCurrentLocation : MonoBehaviour{

  private OnlineMapsMarker playerMarker;
    
    private void Start(){
        // Create a new marker.
    playerMarker = OnlineMaps.instance.AddMarker(new Vector2(0, 0), null, "marker");
        if (locationService == null){
        Debug.LogError(
            "Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service).");
                return;
        }

        // Subscribe to the change location event.
        locationService.OnLocationChanged += OnLocationChanged;

        playerMarker.OnLongPress += OnMarkerLongPress;
        playerMarker.OnRelease += OnMarkerRelease;

    }

// When the location has changed
    private void OnLocationChanged(Vector2 position){
    // Change the position of the marker.
    
    // Redraw map.
    OnlineMaps.instance.Redraw();
    }

    private void OnMarkerLongPress(OnlineMapsMarkerBase playerMarker){
    // Starts moving the marker.
    OnlineMapsControlBase.instance.dragMarker = playerMarker;
    OnlineMapsControlBase.instance.isMapDrag = false;
    }

    private void OnMarkerRelease(OnlineMapsMarkerBase playerMarker){
        
    Debug.Log (playerMarker.position);

    }

}

Re: Get new Lat/Lng after marker drag

Hello.

I tested your code, and it works correctly.
The coordinates of the marker is changes.
Most likely, you just do not see a change because Vector2.ToString shows only one decimal point.
Use:
Debug.Log(playerMarker.position.ToString("F4"));
or
Debug.Log(playerMarker.position.x + "   " + playerMarker.position.y);

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Get new Lat/Lng after marker drag

Great Thanks!  My issue was as I was logging it to the console I was using Debug.Log(playerMarker.position); and it was only logging the Vector2 to only 1 decimal place.
Thanks again for clearing this up.