예제 #1
0
    private void ParseAtmData()
    {
        var file = File.ReadAllText("Assets/Resources/JSON/ATMLocatoinsParsedLondon.txt");

        string[] atmData = file.Split('\n');
        foreach (string datum in atmData)
        {
            string      filer  = datum.Trim(new char[] { '[', ']', });
            string[]    parts  = filer.Split(',');
            ATMLocation newAtm = new ATMLocation(parts[2], float.Parse(parts[1]), float.Parse(parts[0]));
            atmLocations.Add(newAtm);
        }
    }
예제 #2
0
        private async void GetATMs(string location)
        {
            string url = $"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={location}&radius=1500&type=bank&keyword=sterling&key=AIzaSyDYdbG_jHO5TOZcIPkKHsF0uD6po9AWvik";

            var client = new HttpClient();

            try
            {
                string response = await client.GetStringAsync(url);

                var resultObject = JsonConvert.DeserializeObject <ATMs>(response);

                var coordSplit = location.Split(',');

                double lat1 = double.Parse(coordSplit[0]);
                double lon1 = double.Parse(coordSplit[1]);

                if (resultObject.status.ToLower() == "ok")
                {
                    foreach (var place in resultObject.results)
                    {
                        if (place.name.ToLower().Contains("sterling"))
                        {
                            atmLocations.Add(new ATMLocation
                            {
                                PlaceName = place.name,
                                Address   = place.vicinity,
                                Location  = place.geometry.location,
                                Distance  = $"{ATMLocation.GetDistance(lat1, lon1, place.geometry.location.lat, place.geometry.location.lng, DistanceUnit.Kiliometers).ToString("N2")}km",
                                OpenNow   = GetOpenHours(place?.opening_hours?.open_now)
                            });
                        }
                    }

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        ATMPlacesListView.ItemsSource = atmLocations;

                        //Update pin on the map
                        foreach (var item in atmLocations)
                        {
                            map.Pins.Add(new Pin
                            {
                                Position = new Position(item.Location.lat, item.Location.lng),
                                Label    = item.PlaceName,
                                Address  = item.Address,
                                Type     = PinType.Place
                            });
                        }

                        map.SelectedPin = map.Pins.ElementAt(0);
                        map.MoveToRegion(MapSpan.FromCenterAndRadius(map.Pins.ElementAt(0).Position, Distance.FromMeters(500)), true);
                        LoadingView.IsVisible = false;
                    });
                }
            }
            catch (Exception ex)
            {
                LoadingView.IsVisible = false;
                MessageDialog.Show("ATM Places", "Error getting ATM locations at this time.", DialogType.Error, "Retry", () => { GetATMs(location); }, "Cancel", null);

                var log = ex.Message;
                await BusinessLogic.Log(ex.ToString(), "Error getting ATM Locations", url, "", "", "FindATMPage");
            }
        }