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?
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → 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?
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;
}
}
Thanks. The solution works very well.
Infinity Code Forum → Online Maps Help → Check if GPS location reports within map boundaries
Powered by PunBB, supported by Informer Technologies, Inc.