Topic: Check if GPS location reports within map boundaries

We are working on a project that requires to detect if the user GPS location is within the map boundaries. Any suggestions?

Re: Check if GPS location reports within map boundaries

Hello.

Something like that:

using UnityEngine;

public class LocationInMapView:MonoBehaviour
{
    private bool InMapView(double longitude, double latitude)
    {
        double tlx, tly, brx, bry;
        OnlineMaps.instance.GetCorners(out tlx, out tly, out brx, out bry);
        if (latitude > tly || latitude < bry) return false;

        if (tlx > brx)
        {
            brx += 360;
            if (longitude < tlx) longitude += 360;
        }

        return tlx <= longitude && brx >= longitude;
    }

    private void OnLocationChanged(Vector2 location)
    {
        bool inMapView = InMapView(location.x, location.y);
        Debug.Log(inMapView? "In Map View": "Outside Map View");
    }

    private void Start()
    {
        OnlineMapsLocationService.instance.OnLocationChanged += OnLocationChanged;
    }
}
Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: Check if GPS location reports within map boundaries

Thanks. The solution works very well.