Topic: Detect tap on a route drawn with Drawing API

Hi there,

is there the possibility to detect a tap on mobile (or at least a click) on a route drawn with the Drawing API? I want the user to be able to select one of several drawn routes.

Thanks in advance.

Re: Detect tap on a route drawn with Drawing API

Addition to my question, I discovered your example for screen coordinate to geographic coordinate conversion.
I adapted the script for touch position like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DetectTapOnRoute : MonoBehaviour
    public OnlineMapsControlBase control;

    void Start()
        if (control == null) control = OnlineMapsControlBase.instance;

    // Update is called once per frame
    void Update()
        if (Input.touchCount > 0)
            Touch touch = Input.GetTouch(0);
            // Screen coordinate of the touch.
            Vector3 touchPosition = new Vector3(touch.position.x, touch.position.y, 0);

            // Converts the screen coordinates to geographic.
            Vector3 touchGeoLocation = control.GetCoords(touchPosition);

            // Showing geographical coordinates in the console.
            Debug.Log("touch geo location " + touchGeoLocation);

But it doesn't work reliably yet. Of course, when dragging the map, I get back 0,0,0.

Unfortunately I also get 0,0,0 most of the time when tapping on random positions on the map.
In between, there are some random successful hits with kind of fitting geographic coordinates, but I only get back coordinates (other than 0,0,0) for like 10% of the taps. Any ideas on why it only works for a fraction of my taps?

Re: Detect tap on a route drawn with Drawing API


Use Drawing Element events.
Example: … ample.html

Kind Regards,
Infinity Code Team.

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

Re: Detect tap on a route drawn with Drawing API

Hi Alex, oh my, I must have missed this lol
I actually searched the example atlas for 'tap' or 'click', but nothing fitting came up. Thanks for pointing me in the right direction, that is exactly what I need smile