private async void SetMapa() { var restMaps = new RestMaps(); var listaPostos = await restMaps.GetPostoAsync(); if (listaPostos != null) { foreach (var obj in listaPostos.results) { if (obj.geometry.location.lat != 0 && obj.geometry.location.lng != 0) { MyMap.IsVisible = true; var position = new Position(obj.geometry.location.lat, obj.geometry.location.lng); // Latitude, Longitude var pin = new Pin { Type = PinType.Place, Position = position, Label = obj.name, Address = obj.vicinity }; MyMap.Pins.Add(pin); } } await SetMyPosition(); } }
private async void SetMapa() { await SetMyPosition(); var restMaps = new RestMaps(); var listaPostos = await restMaps.GetPostoAsync(); if (listaPostos != null && MyPosition != null) { double Distancia = 999; foreach (var obj in listaPostos.results) { if (obj.geometry.location.lat != 0 && obj.geometry.location.lng != 0) { var position = new Position(obj.geometry.location.lat, obj.geometry.location.lng); // Latitude, Longitude var pin = new Pin { Type = PinType.Place, Position = position, Label = obj.name, Address = obj.vicinity }; MyMap.Pins.Add(pin); // VERIFICA SE É O POSTO MAIS PROXIMO DO USUARIO double DistanciaAtual = Utils.Distance(MyPosition.Latitude.ToString(), MyPosition.Longitude.ToString(), obj.geometry.location.lat.ToString(), obj.geometry.location.lng.ToString()); if (DistanciaAtual < Distancia) { Distancia = DistanciaAtual; PostoProximo = position; } } } await RotateImageContinously(false); } else { await Application.Current.MainPage.DisplayAlert("Que pena!", "Não foi possível localizar a posição do GPS", "OK"); await Navigation.PopAsync(); } }