internal static void OnReady(GeolocationEvent success,GeolocationErrorEvent error,GeoPositionOptions options){ // High accuracy: bool highAcc=(options!=null && options.enableHighAccuracy); // Age: double maxAge=(options==null)?0 : options.maximumAge; if(options!=null && options.maximumAge!=0 && Latest!=null){ // Can we recycle latest? if(Latest.age<maxAge){ // yep! if(success!=null){ success(Latest); } return; } } // Get service: LocationService ls=UnityEngine.Input.location; if(ls.status==LocationServiceStatus.Failed){ // Error - failed. if(error!=null){ error(new GeoPositionError(GeoPositionError.POSITION_UNAVAILABLE)); } return; } // Create: GeoPosition pos=new GeoPosition(ls.lastData,highAcc); // Ok! if(success!=null){ success(pos); } }
/// <summary>Gets the current position.</summary> public void getCurrentPosition(GeolocationEvent success, GeolocationErrorEvent error, GeoPositionOptions options) { // Get service: LocationService ls = UnityEngine.Input.location; if (!ls.isEnabledByUser) { // Denied. if (error != null) { error(new GeoPositionError(GeoPositionError.PERMISSION_DENIED)); } return; } // Started yet? if (ls.status == LocationServiceStatus.Stopped) { // Start now: ls.Start(); } else if (ls.status != LocationServiceStatus.Initializing) { // Call ready now: OnReady(success, error, options); return; } // Enqueue, taking our timeout into account. PendingLocationRequest node = new PendingLocationRequest(); // Apply settings: node.Success = success; node.Error = error; node.Options = options; if (options != null && options.timeout != 0f) { // Get timeout in seconds: node.Timeout = (float)options.timeout / 1000f; } node.Next = FirstQueued; FirstQueued = node; if (Updater == null) { // Start calling update now at 10fps: OnUpdate.Add(Update, 10f); } }