public async void pollLocation(string parameters) { if (!polling) { polling = true; string[] args = WPCordovaClassLib.Cordova.JSON.JsonHelper.Deserialize <string[]>(parameters); int watchId = int.Parse(args[0]); MobiLocationListener listen = listeners.Where <MobiLocationListener>(x => x.index == watchId).FirstOrDefault(); if (listen != null) { Geoposition geoposition = await GetPosition(listen.maxAge, listen.highAccuracy); Geocoordinate cord = geoposition.Coordinate; System.Globalization.CultureInfo ci = new CultureInfo("en-US"); // AppMobi.Geolocation.prototype.successCB = function (ID, latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed, timestamp) { var js = string.Format(ci, "javascript:intel.xdk.geolocation.successCB({0},{1},{2},{3},{4},{5},{6},{7},'{8}');", listen.successID, (cord.Latitude != null) ? cord.Latitude : 0.00, (cord.Longitude != null) ? cord.Longitude : 0.00, (cord.Altitude != null) ? cord.Altitude : 0.00, (cord.Accuracy != null) ? cord.Accuracy : 0.00, (cord.AltitudeAccuracy != null) ? cord.AltitudeAccuracy : 0.00, (cord.Heading.HasValue && !Double.IsNaN(cord.Heading.Value)) ? cord.Heading : 0.00, (cord.Speed.HasValue && !Double.IsNaN(cord.Speed.Value)) ? cord.Speed : 0.00, cord.Timestamp); //InjectJS(js); InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true); } polling = false; } }
public void clearWatch(string parameters) { string[] args = WPCordovaClassLib.Cordova.JSON.JsonHelper.Deserialize <string[]>(parameters); int watchId = 0; int.TryParse(args[0], out watchId); MobiLocationListener listen = listeners.Where <MobiLocationListener>(x => x.index == watchId).FirstOrDefault(); listeners.Remove(listen); DispatchCommandResult(new PluginResult(PluginResult.Status.OK, watchId)); }
public void watchPosition(string parameters) { string[] args = WPCordovaClassLib.Cordova.JSON.JsonHelper.Deserialize <string[]>(parameters); int currentWatchId = watchId; successCallbackID = (args.Length > 0) ? int.Parse(args[0]) : 0; errorCallbackID = (args.Length > 1) ? int.Parse(args[1]) : 0; maximumAge = (args.Length > 3) ? int.Parse(args[3]) : 0; highAccuracy = (args.Length > 4) ? bool.Parse(args[4]) : false; MobiLocationListener mobiList = new MobiLocationListener(watchId, false, successCallbackID, errorCallbackID, maximumAge, highAccuracy); listeners.Add(mobiList); watchId++; DispatchCommandResult(new PluginResult(PluginResult.Status.OK, currentWatchId)); }