// Use this for initialization void Start () { backDropActive = GameObject.Find ("locationbackdrop"); check = GameObject.Find ("LocationUIText").GetComponent<LocationUpdate> (); }
private bool BeginListening() { if (LocationUpdate != null) { try { var request = new GeolocationRequest(GeolocationAccuracy.High, new TimeSpan(0, 0, 2)); // This can't be called from a background thread, bug https://github.com/xamarin/Essentials/issues/634 var task = Geolocation.GetLocationAsync(request); task.ContinueWith(x => { try { if (x.IsCompleted) { var location = x.Result; if (location == null) { _location.Update("Timed out getting location"); Alert?.Invoke(this, new AlertEventArgs(true)); } else { _location.Update(location.Latitude, location.Longitude, location.Accuracy, location.Altitude, location.Speed, location.Course, location.Timestamp); Alert?.Invoke(this, new AlertEventArgs(false)); } } } catch { _location.Update("Unknown error"); Alert?.Invoke(this, new AlertEventArgs(true)); } }, TaskScheduler.FromCurrentSynchronizationContext()); } catch (FeatureNotSupportedException e) { // Handle not supported on device exception _location.Update(string.Format("{0}", e.Message)); Alert?.Invoke(this, new AlertEventArgs(true)); } catch (PermissionException e) { // Handle permission exception _location.Update(string.Format("{0}", e.Message)); Alert?.Invoke(this, new AlertEventArgs(true)); } catch (Exception e) { // Unable to get location _location.Update(string.Format("{0}", e.Message)); Alert?.Invoke(this, new AlertEventArgs(true)); } LocationUpdate?.Invoke(this, new LocationEventArgs(_location)); } return(true); }
/// <summary> /// Send new message to hub. /// </summary> /// <param name="methodName"></param> /// <param name="locationUpdate"></param> /// <returns></returns> public async Task SendHubMessage(string methodName, LocationUpdate locationUpdate) { await _hub?.InvokeAsync(methodName, locationUpdate); }
public override void SetLocation(LocationUpdate update, bool interpolate) { }
/// <summary> /// Handle location update message and broadcast it to all connected clients. /// </summary> /// <param name="locationUpdate"></param> public void BroadcastMessage(LocationUpdate locationUpdate) { Clients.All.SendAsync("broadcastMessage", locationUpdate); }
public static async Task <object> RunUpdateGeolocation([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log) { log.Info($"Webhook was triggered!"); GraphInfo cdaInfo = null; #if DEBUG cdaInfo = new GraphInfo { UserPrincipalName = "*****@*****.**" }; #else cdaInfo = await GetCDAGraphInfo(req, log); if (cdaInfo == null) { return(req.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error using the Graph")); } #endif var jsonContent = await req.Content.ReadAsStringAsync(); LocationUpdate data = null; if (!string.IsNullOrWhiteSpace(jsonContent)) { data = JsonConvert.DeserializeObject <LocationUpdate>(jsonContent); } #if DEBUG else { data = new LocationUpdate { Position = new Microsoft.Azure.Documents.Spatial.Point(-122.130602, 47.6451599), Mood = "🐒" } }; #endif var key = System.Environment.GetEnvironmentVariable("BingMapsKey", EnvironmentVariableTarget.Process); //if we can't detect the city in app, let's figure it out! if (string.IsNullOrWhiteSpace(data.Country) || string.IsNullOrWhiteSpace(data.State) || string.IsNullOrWhiteSpace(data.Town)) { var reverse = await ServiceManager.GetResponseAsync(new ReverseGeocodeRequest() { BingMapsKey = key, Point = new Coordinate(data.Position.Position.Latitude, data.Position.Position.Longitude), IncludeEntityTypes = new System.Collections.Generic.List <EntityType> { EntityType.CountryRegion, EntityType.Address, EntityType.AdminDivision1 } }); var result1 = reverse.ResourceSets.FirstOrDefault()?.Resources.FirstOrDefault() as BingMapsRESTToolkit.Location; if (result1 != null) { //update the city/state here data.State = result1.Address.AdminDistrict; data.Country = result1.Address.CountryRegion; data.Town = result1.Address.Locality; } } //find the generic lat/long var r = await ServiceManager.GetResponseAsync(new GeocodeRequest() { BingMapsKey = key, Query = $"{data.Town}, {data.State} {data.Country}" }); var result2 = r.ResourceSets.FirstOrDefault()?.Resources.FirstOrDefault() as BingMapsRESTToolkit.Location; var point = result2?.GeocodePoints?.FirstOrDefault()?.GetCoordinate(); if (point != null) { data.Position = new Microsoft.Azure.Documents.Spatial.Point(point.Longitude, point.Latitude); } else { //blank out lat/long data.Position = new Microsoft.Azure.Documents.Spatial.Point(-122.1306030, 47.6451600); } //update cosmos DB here data.UserPrincipalName = cdaInfo.UserPrincipalName; data.InsertTime = DateTimeOffset.UtcNow; #if !DEBUG var doc = await docClient.CreateDocumentAsync(locationCollectionUri, data); #endif return(req.CreateResponse(HttpStatusCode.OK, new { greeting = $"Hello {data.UserPrincipalName}, you are in {data.Country} {data.Town}!" })); }
public Task LocationUpdate(LocationUpdate locationUpdate) { return(Clients.All.SendAsync("location-update", locationUpdate)); }
private void reader_LocationUpdated(object sender, ClientModels.EDLog e) { LocationUpdate?.Invoke(this, e.Location); }