Example #1
0
        public App()
        {
            var map = new MapExtend()
            {
                IsShowingUser = true,
                HeightRequest = 100,
                WidthRequest = 960,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            var entryEnd = new Entry
            {
                Placeholder = "Address",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            var btnSearch = new Button
            {
                Text = "Add",
                BackgroundColor = Color.Transparent,
                BorderColor = Color.Transparent
            };

            var btnCreateRoute = new Button
            {
                Text = "Route",
                BackgroundColor = Color.Transparent,
                BorderColor = Color.Transparent
            };

            var barItens = new StackLayout
            {
                Orientation = StackOrientation.Horizontal
            };

            btnSearch.Clicked += async (sender, args) =>
            {
                await map.SearchAdress(entryEnd.Text).ContinueWith(t =>
                {
                    var d = t;
                });

                entryEnd.Text = string.Empty;
                entryEnd.Unfocus();
            };

            barItens.Children.Add(entryEnd);
            barItens.Children.Add(btnSearch);

            btnCreateRoute.Clicked += async (sender, args) =>
            {
                await map.CreateRoute(map.Pins[0].Position, map.Pins[1].Position).ContinueWith(t =>
                {
                    var d = t;
                });
            };

            var btnNearbyLocation = new Button
            {
                Text = "Nearby Pleaces"
            };

            btnNearbyLocation.Clicked += async (sender, args) =>
            {
                await map.NearbyLocations("AIzaSyBuATAkE41ioaMXd6MvWOmFlG2p-MlE6HM", "").ContinueWith(t =>
                {
                    var d = t;
                });

            };

            var stack = new StackLayout
            {
                Spacing = 0,
                Children = { barItens, map, btnCreateRoute, btnNearbyLocation }
            };

            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            var geoLocation = locator.GetPositionAsync().ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    //System.Diagnostics.Debug.WriteLine("Error : {0}", ((GeolocationException)t.Exception.InnerException).Error.ToString());
                }
                else if (t.IsCanceled)
                {
                    System.Diagnostics.Debug.WriteLine("Error : The geolocation has got canceled !");
                }
                else
                {
                    var currentLocation = new Position(t.Result.Latitude, t.Result.Longitude);

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        map.MoveToRegion(MapSpan.FromCenterAndRadius(currentLocation, Xamarin.Forms.Maps.Distance.FromMiles(0.5)));
                        map.EPins.Add(new PinExtend{ Name= "seu endereço", Location= currentLocation, Details = "seu endreço", ResourceNameImg = "icon" });
                    });
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());

            // The root page of your application
            MainPage = new ContentPage
            {
                Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5),
                Content = stack
            };
        }
Example #2
0
        private MapPage(string newPinName)
        {
            _map = new MapExtend
            {
                IsShowingUser = true,
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            ((ObservableCollection<Pin>)_map.Pins).CollectionChanged += (o, e) =>
            {
                // reset pin names to be the provided name
                if (e.NewItems != null)
                    foreach (Pin pin in e.NewItems)
                        pin.Label = newPinName;
            };

            #region search
            Label searchLabel = new Label
            {
                Text = "Address:",
                FontSize = 20
            };

            _searchEntry = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            Button searchGoButton = new Button
            {
                Text = "Go",
                FontSize = 20
            };

            searchGoButton.Clicked += (o, e) =>
            {
                if (!string.IsNullOrWhiteSpace(_searchEntry.Text))
                    _map.SearchAdress(_searchEntry.Text);
            };
            #endregion

            Button clearPinsButton = new Button
            {
                Text = "Clear Pins",
                FontSize = 20,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            clearPinsButton.Clicked += (o, e) =>
            {
                _map.Pins.Clear();
            };

            Content = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children =
                {
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children = { searchLabel, _searchEntry, searchGoButton }
                    },
                    clearPinsButton,
                    _map,
                }
            };
        }
Example #3
0
        private MapPage(string newPinName)
        {
            _map = new MapExtend
            {
                IsShowingUser = true,
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            ((ObservableCollection<Pin>)_map.Pins).CollectionChanged += (o, e) =>
            {
                // reset pin names to be the provided name
                if (e.NewItems != null)
                    foreach (Pin pin in e.NewItems)
                        pin.Label = newPinName;
            };

            #region search
            Label searchLabel = new Label
            {
                Text = "Search:",
                FontSize = 20
            };

            _searchEntry = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            Button searchGoButton = new Button
            {
                Text = "Go",
                FontSize = 20
            };

            searchGoButton.Clicked += (o, e) =>
            {
                if (!string.IsNullOrWhiteSpace(_searchEntry.Text))
                {
                    try
                    {
                        _map.SearchAdress(_searchEntry.Text);
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            string errorMessage = "Failed to search for address:  " + ex.Message;
                            SensusServiceHelper.Get().Logger.Log(errorMessage, SensusService.LoggingLevel.Normal, GetType());
                            SensusServiceHelper.Get().FlashNotificationAsync(errorMessage);                            
                        }
                        catch (Exception)
                        {
                        }
                        finally
                        {
                            Insights.Report(ex, Insights.Severity.Warning);
                        }
                    }
                }
            };
            #endregion

            Button clearPinsButton = new Button
            {
                Text = "Clear Pins",
                FontSize = 20,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            clearPinsButton.Clicked += (o, e) =>
            {
                _map.Pins.Clear();
            };

            Button okButton = new Button
            {
                Text = "OK",
                FontSize = 20,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            okButton.Clicked += async (o, e) =>
            {
                await Navigation.PopModalAsync();
            };

            Content = new StackLayout
            { 
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 20, 0, 0),
                Children =
                {                     
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children = { searchLabel, _searchEntry, searchGoButton }
                    },
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children = { clearPinsButton, okButton }
                    },
                    _map,
                }
            };
        }