Topic: OnMapPress/LongPress doesnot fired for android

Hello,
I experience weired situation. I used the sprite control earlier but I find many post recommending using the tileset.
So I changed to tileset. However, the  problem still persist. I work fine when running on the Editor. but once building into  the mobile. No event fired:

OnlineMapsControlBase.instance.OnMapLongPress += OnMapLongPressed;

any ideas?

Re: OnMapPress/LongPress doesnot fired for android

Hello.

I have tested this and it works correctly on my side.
The APK is attached.
Test script:

using System.Collections.Generic;
using UnityEngine;

public class TestMapPress : MonoBehaviour
{
    private List<string> messages = new List<string>();
    private string displayMessage = "";

    private void OnGUI()
    {
        GUILayout.Label(displayMessage);
    }

    private void Start()
    {
        OnlineMapsControlBase.instance.OnMapPress += () => Log("Press");
        OnlineMapsControlBase.instance.OnMapLongPress += () => Log("LongPress");
    }

    private void Log(string message)
    {
        messages.Insert(0, message);
        while (messages.Count > 20)
        {
            messages.RemoveAt(messages.Count - 1);
        }

        displayMessage = string.Join("\n", messages);
    }
}

If you want, you can send me your project by email (support@infinity-code.com), and I'll check why it doesn't work on your side.

Post's attachments

Attachment icon test.apk 31 mb, 75 downloads since 2020-08-23 

Kind Regards,
Infinity Code Team.

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

Re: OnMapPress/LongPress doesnot fired for android

Hi, I tried your APK but still not working with my device (SS Galaxy S8) . I have no idea why. I can just zoom in/out and tilt. No long press event shown up.
Anyway,
I tried to dbug and added many comments into codes and suddenly found another weired unity's behaviour. I added debug messages along OnMapBasePress() also in WaitLongPress() coroutine. I found the coroutine just stuck at before the line
yield return watiforsecond (longpressDelay);  No thing printed after that line.

Then, I tried to fix without any clues, so I went to OnMapBaseRelease() and just add two debug messages. Then I have no idea why it work now.

Please trust me about what I said. I have stucked at this issue for 3 days before it gets fixed with big doubt.



protected virtual void OnMapBasePress()
    {
        isMapPress = false;
        Debug.Log("ismapPress=false"); //--------------------> added here

        if (waitZeroTouches)
        {
            if (GetTouchCount() <= 1) waitZeroTouches = false;
            else return;
        }
        Debug.Log("Waitzerotouches"); //--------------------> added here
        dragMarker = null;
        Vector2 inputPosition = GetInputPosition();
        Debug.Log("get position"); //--------------------> added here
        if (!HitTest(inputPosition)) return;
        Debug.Log("hit test!!!"); //--------------------> added here
        if (IsCursorOnUIElement(inputPosition)) return;
        Debug.Log("cursor on UI Element");

        if (OnMapPress != null) OnMapPress();
        Debug.Log("Map pressed"); //--------------------> added here
        lastClickTimes[0] = lastClickTimes[1];
        lastClickTimes[1] = Time.realtimeSinceStartup;

        double tx, ty;
        lastInputPosition = pressPoint = inputPosition;
        if (!GetTile(inputPosition, out tx, out ty)) return;
        Debug.Log("can't get tile"); //--------------------> added here
        isMapPress = true;

        OnlineMapsMarkerBase marker = null;
        OnlineMapsDrawingElement drawingElement = null;

        IOnlineMapsInteractiveElement interactiveElement = GetInteractiveElement(inputPosition);

        if (interactiveElement != null)
        {
            if (interactiveElement is OnlineMapsMarkerBase) marker = interactiveElement as OnlineMapsMarkerBase;
            else if (interactiveElement is OnlineMapsDrawingElement) drawingElement = interactiveElement as OnlineMapsDrawingElement;
        }

        if (marker != null)
        {
            if (marker.OnPress != null) marker.OnPress(marker);
            if (map.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onPress)
            {
                OnlineMapsTooltipDrawerBase.tooltipMarker = marker;
                OnlineMapsTooltipDrawerBase.tooltip = marker.label;
            }
            if (Input.GetKey(KeyCode.LeftControl)) dragMarker = marker;
        }
        else if (drawingElement != null)
        {
            if (drawingElement.OnPress != null) drawingElement.OnPress(drawingElement);
            if (map.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onPress)
            {
                OnlineMapsTooltipDrawerBase.tooltipDrawingElement = drawingElement;
                OnlineMapsTooltipDrawerBase.tooltip = drawingElement.tooltip;
            }
        }

        if (dragMarker == null) isMapDrag = true;

        activeElement = interactiveElement;
        Debug.Log("wait long pressed"); //--------------------> added here
        if (longPressEnumerator == null)
        {
            longPressEnumerator = WaitLongPress();       
            StartCoroutine(longPressEnumerator);
        }
   
        if (allowUserControl) OnlineMaps.isUserControl = true;
    }


===================================================
  private IEnumerator WaitLongPress()
    {
       
        Debug.Log("wait long pressed..."+longPressDelay); //--------------------> added here

        //yield return new WaitForSeconds(longPressDelay);
        float t = 0;
        while (t < longPressDelay)
        {
            yield return null;
            t += Time.deltaTime;
        }


        OnlineMapsMarkerBase marker = null;
        OnlineMapsDrawingElement drawingElement = null;
        Vector2 inputPosition = GetInputPosition();
        Debug.Log("inputPosition" );  //--------------------> added here
        IOnlineMapsInteractiveElement interactiveElement = GetInteractiveElement(inputPosition);
        Debug.Log("interactiveElement");
        if (interactiveElement != null)
        {
            if (interactiveElement is OnlineMapsMarkerBase) marker = interactiveElement as OnlineMapsMarkerBase;
            else if (interactiveElement is OnlineMapsDrawingElement) drawingElement = interactiveElement as OnlineMapsDrawingElement;
        }
        Debug.Log("marker");
        if (marker != null && marker.OnLongPress != null) { marker.OnLongPress(marker); Debug.Log("marker longpress"); }
        else if (drawingElement != null && drawingElement.OnLongPress != null) { drawingElement.OnLongPress(drawingElement); Debug.Log("drawing element"); }
        else if (OnMapLongPress != null)
        {
            Debug.Log("finally long pressed");//--------------------> added here
            OnMapLongPress();
            isMapDrag = false;
        }
        Debug.Log("wait long pressed end");//--------------------> added here
        longPressEnumerator = null;
       
    }


===================================================
protected virtual void OnMapBaseRelease()
    {
        Debug.Log("Release"); //=> I added here then the problem solved........???!!!!!******
        if (waitZeroTouches && GetTouchCount() == 0) waitZeroTouches = false;
        if (GUIUtility.hotControl != 0) return;

        Vector2 inputPosition = GetInputPosition();
        bool isClick = (pressPoint - inputPosition).sqrMagnitude < 400 && !lockClick;
        lockClick = false;
        isMapDrag = false;
        mapDragStarted = false;
        dragMarker = null;

        if (longPressEnumerator != null)
        {
            StopCoroutine(longPressEnumerator);
            longPressEnumerator = null;
            Debug.Log("stop coroutine"); //=> I added here then the problem solved........???!!!!!******
        }

        lastInputPosition = Vector2.zero;
        OnlineMaps.isUserControl = false;

        if (!isMapPress) return;
        isMapPress = false;
        if (OnMapRelease != null) OnMapRelease();

        OnlineMapsMarkerBase marker = null;
        OnlineMapsDrawingElement drawingElement = null;

        IOnlineMapsInteractiveElement interactiveElement = GetInteractiveElement(inputPosition);

        if (interactiveElement != null)
        {
            if (interactiveElement is OnlineMapsMarkerBase) marker = interactiveElement as OnlineMapsMarkerBase;
            else if (interactiveElement is OnlineMapsDrawingElement) drawingElement = interactiveElement as OnlineMapsDrawingElement;
        }

        if (map.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onPress && (OnlineMapsTooltipDrawerBase.tooltipMarker != null || OnlineMapsTooltipDrawerBase.tooltipDrawingElement != null))
        {
            OnlineMapsTooltipDrawerBase.tooltipMarker = null;
            OnlineMapsTooltipDrawerBase.tooltipDrawingElement = null;
            OnlineMapsTooltipDrawerBase.tooltip = null;
        }

        bool isClicked = false;

        if (marker != null)
        {
            if (marker.OnRelease != null) marker.OnRelease(marker);
            if (isClick && marker.OnClick != null)
            {
                marker.OnClick(marker);
                isClicked = true;
            }
        }
        else if (drawingElement != null)
        {
            if (drawingElement.OnRelease != null) drawingElement.OnRelease(drawingElement);
        }

        if (activeElement != null && activeElement != interactiveElement)
        {
            if (activeElement is OnlineMapsMarkerBase)
            {
                OnlineMapsMarkerBase m = activeElement as OnlineMapsMarkerBase;
                if (m.OnRelease != null) m.OnRelease(m);
            }
            else if (activeElement is OnlineMapsDrawingElement)
            {
                OnlineMapsDrawingElement d = activeElement as OnlineMapsDrawingElement;
                if (d.OnRelease != null) d.OnRelease(d);
            }
            activeElement = null;
        }

        if (isClick && Time.realtimeSinceStartup - lastClickTimes[0] < 0.5f)
        {
            if (marker != null && marker.OnDoubleClick != null) marker.OnDoubleClick(marker);
            else if (drawingElement != null && drawingElement.OnDoubleClick != null) drawingElement.OnDoubleClick(drawingElement);
            else
            {
                if (OnMapDoubleClick != null) OnMapDoubleClick();

                if (allowZoom && zoomInOnDoubleClick)
                {
                    if (!((marker != null && marker.OnClick != null) || (drawingElement != null && drawingElement.OnClick != null)))
                    {
                        if (OnValidateZoom == null || OnValidateZoom(OnlineMapsZoomEvent.doubleClick, map.floatZoom + 1))
                        {
                            if (zoomMode == OnlineMapsZoomMode.target) ZoomOnPoint(1, inputPosition);
                            else map.floatZoom += 1;
                        }
                    }
                }
            }
           
            lastClickTimes[0] = 0;
            lastClickTimes[1] = 0;
        }
        else if (isClick && !isClicked)
        {
            if (drawingElement != null && drawingElement.OnClick != null) drawingElement.OnClick(drawingElement);
            else if (OnMapClick != null) OnMapClick();
        }

        if (map.bufferStatus == OnlineMapsBufferStatus.wait) map.needRedraw = true;
    }

Re: OnMapPress/LongPress doesnot fired for android

Hello
I'm sorry to say the problem actually still exist.
I am trying out something else like using tileset UI example as a template scene.
I will update tomorrow if it works

Re: OnMapPress/LongPress doesnot fired for android

Before attaching the APK, I checked it on my side and it works correctly.

Are you sure your device's sensor is working correctly?
You are the first who report this issue, and I have good reason to believe that the problem is with the device.
Have you tested your app and/or my APK on other devices?
If this works correctly on other devices, then you need to check the sensor of your device through the phone's engineering menu, or using third-party apps.
If this still does not work correctly on other devices, let me know and we will look for the reason why this is happening.

Kind Regards,
Infinity Code Team.

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

Re: OnMapPress/LongPress doesnot fired for android

Hi there,
I can now make it works
I started from duplicating your example scene and copy my code into the scene.
I think The problem may has something to do firebase library in start().
Anyway, it works now thank you for your advice and support.