Topic: How to get coordinates of 4 corners on mobile screen

Hi
I'm trying to get coordinates of 4 corners on screen of mobile to get all markers among that 4 corners. And their coordinate must be updated when I zoom in/out.
But I don't know how to do this. I used OnlineMapsControlBase.GetCoords, but it is not working.
Is there any way to do this?
Thanks!

Re: How to get coordinates of 4 corners on mobile screen

Hello.

Yes, you need to use OnlineMapsControlBase.GetCoords.
Example:

using UnityEngine;

public class GetCoordinatesOfScreenCorners:MonoBehaviour
{
    public static void LogCorners()
    {
        double lng, lat;

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(0, 0));
        Debug.Log("Bottom left longitude: " + lng + ", latitude: " + lat);

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(Screen.width, 0));
        Debug.Log("Bottom right longitude: " + lng + ", latitude: " + lat);

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(Screen.width, Screen.height));
        Debug.Log("Top right longitude: " + lng + ", latitude: " + lat);

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(0, Screen.height));
        Debug.Log("Top left longitude: " + lng + ", latitude: " + lat);
    }

    private void OnGUI()
    {
        if (GUILayout.Button("Log corners")) LogCorners();
    }
}
Kind Regards,
Infinity Code Team.

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

Re: How to get coordinates of 4 corners on mobile screen

Alex Vertax wrote:

Hello.

Yes, you need to use OnlineMapsControlBase.GetCoords.
Example:

using UnityEngine;

public class GetCoordinatesOfScreenCorners:MonoBehaviour
{
    public static void LogCorners()
    {
        double lng, lat;

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(0, 0));
        Debug.Log("Bottom left longitude: " + lng + ", latitude: " + lat);

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(Screen.width, 0));
        Debug.Log("Bottom right longitude: " + lng + ", latitude: " + lat);

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(Screen.width, Screen.height));
        Debug.Log("Top right longitude: " + lng + ", latitude: " + lat);

        OnlineMapsControlBase.instance.GetCoords(out lng, out lat, new Vector2(0, Screen.height));
        Debug.Log("Top left longitude: " + lng + ", latitude: " + lat);
    }

    private void OnGUI()
    {
        if (GUILayout.Button("Log corners")) LogCorners();
    }
}

thanks!