예제 #1
0
        async void Uber_tapped(object sender, System.EventArgs e)
        {
            var     MapsAddressPlus = AddPlusToMapAddress(MapsAddress);
            var     encodedAddress  = HttpUtility.UrlEncode(MapsAddress);
            string  deepLink        = "";
            LatLong ll   = new LatLong();
            Uber    uber = new Uber();

            string map = "";

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                map = "Apple";
                break;

            case Device.Android:
                map = "Android";
                break;


            default:
                map = "Not android/IOS";
                break;
            }

            using (UserDialogs.Instance.Loading("Loading...."))
            {
                try
                {
                    var coordinates = await ll.CalcLongLat(MapsAddress);

                    if (!string.IsNullOrEmpty(coordinates.Latitude.ToString()) &&
                        (!string.IsNullOrEmpty(coordinates.Longitude.ToString())))
                    {
                        deepLink = uber.GetUberDeepLink(coordinates.Longitude,
                                                        coordinates.Latitude, encodedAddress);
                        Device.BeginInvokeOnMainThread(() => Device.OpenUri(new Uri(deepLink)));
                    }
                    else
                    {
                        await DisplayAlert("Lat/Long Issue", "Can not get the latitude/longitude of the selected location", "OK");
                    }
                }


                catch (FeatureNotSupportedException fnsEx)
                {
                    await DisplayAlert("Faild", fnsEx.Message, "OK");
                }
                catch (PermissionException pEx)
                {
                    await DisplayAlert("Faild", pEx.Message, "OK");
                }


                catch (Exception ex)
                {
                    var log = ex;

                    try
                    {
                        var msg = "Navigating to uber. " +
                                  "Please take note of the destination address";
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            var fakeClick = true;//i was pressed for time so i just hardcoded this. wil corrct later
                            if (fakeClick)
                            {
                                using (UserDialogs.Instance.Loading(""))
                                {
                                    IGeocoder geocoder = new GoogleGeocoder()
                                    {
                                        ApiKey = "AIzaSyBeq5wC6XqvGG73TGPDzqJkx - WFwG6uqx4"
                                    };
                                    IEnumerable <Address> addresses = await geocoder.GeocodeAsync(MapsAddress);

                                    //Console.WriteLine("Formatted: " + addresses.First().FormattedAddress); //Formatted: 1600 Pennsylvania Ave SE, Washington, DC 20003, USA
                                    if (addresses != null)
                                    {
                                        var lat       = addresses.First().Coordinates.Latitude;
                                        var longitude = addresses.First().Coordinates.Longitude;
                                        deepLink = uber.GetUberDeepLink(longitude, lat, MapsAddress, hostOrEventName);
                                        // deepLink = await ll.ReturnUberDeepLinkNonPrecise(MapsAddress);
                                        Device.BeginInvokeOnMainThread(() => Device.OpenUri(new Uri(deepLink)));
                                    }
                                    else
                                    {
                                        await DisplayAlert("", "Can not get longitude and latitude. Manually search uber", "OK");
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception exx)
                    {
                        await DisplayAlert("", "Error occured", "OK");

                        var logg = exx;
                    }
                }
            }
        }