Ejemplo n.º 1
0
        public AddRoutePage(ObservableCollection<TKRoute> routes, ObservableCollection<TKCustomMapPin> pins, MapSpan bounds)
        {
            InitializeComponent();

            var googleImage = new Image 
            {
                Source = "powered_by_google_on_white.png"
            };

            var searchFrom = new PlacesAutoComplete(false) { ApiToUse = PlacesAutoComplete.PlacesApi.Native, Bounds = bounds, Placeholder = "From" };
            searchFrom.SetBinding(PlacesAutoComplete.PlaceSelectedCommandProperty, "FromSelectedCommand");
            var searchTo = new PlacesAutoComplete(false) { ApiToUse = PlacesAutoComplete.PlacesApi.Native, Bounds = bounds, Placeholder = "To" };
            searchTo.SetBinding(PlacesAutoComplete.PlaceSelectedCommandProperty, "ToSelectedCommand");

            if (Device.OS == TargetPlatform.Android)
            {
                this._baseLayout.Children.Add(
                    googleImage,
                    Constraint.Constant(10),
                    Constraint.RelativeToParent(l => l.Height - 30));
            }

            this._baseLayout.Children.Add(
                searchTo,
                yConstraint: Constraint.RelativeToView(searchFrom, (l, v) => searchFrom.HeightOfSearchBar + 10));

            this._baseLayout.Children.Add(
                searchFrom,
                Constraint.Constant(0),
                Constraint.Constant(10));

            this.BindingContext = new AddRouteViewModel(routes, pins, bounds);
        }
Ejemplo n.º 2
0
		public MapViewModel()
		{
//			Position = App.GPS.LastKnownPosition;
			visibleRegion = MapSpan.FromCenterAndRadius(new Position(0, 0), Distance.FromMeters(1000));

			MapOrientation = MapOrientation.NorthUp;
		}
Ejemplo n.º 3
0
        ///<inheritdoc/>
        public async Task<IEnumerable<IPlaceResult>> GetPredictions(string query, MapSpan bounds)
        {
            List<IPlaceResult> result = new List<IPlaceResult>();

            var region = new MKCoordinateRegion(bounds.Center.ToLocationCoordinate(), new MKCoordinateSpan(0.25, 0.25));

            var request = new MKLocalSearchRequest 
            {
                NaturalLanguageQuery = query,
                Region = region
            };

            MKLocalSearch search = new MKLocalSearch(request);
            var nativeResult = await search.StartAsync();

            if (nativeResult != null && nativeResult.MapItems != null)
            {
                result.AddRange(nativeResult.MapItems.Select(i =>
                    new TKNativeiOSPlaceResult
                    {
                        Description =  string.Format("{0}, {1} {2}", i.Placemark.Title, i.Placemark.AdministrativeArea, i.Placemark.SubAdministrativeArea),
                        Details = new TKPlaceDetails 
                        {
                            Coordinate = i.Placemark.Coordinate.ToPosition()
                        }
                    }));
                return result;
            }
            return null;
        }
Ejemplo n.º 4
0
        public new void MoveToRegion(MapSpan mapSpan)
        {
            if (Device.OS != TargetPlatform.iOS)
                base.MoveToRegion(mapSpan);

            Console.WriteLine(mapSpan.Radius.Kilometers.ToString());
            OnRegionMoved(new MapRegionMoveEventArgs(mapSpan.Center.Latitude, mapSpan.Center.Longitude, (mapSpan.Radius.Kilometers == 2) ? 13 : 11));
        }
Ejemplo n.º 5
0
		public void Constructor ()
		{
			var span = new MapSpan (new Position(0, 0), 1, 1);

			Assert.AreEqual (new Position (0, 0), span.Center);
			Assert.AreEqual (1, span.LatitudeDegrees);
			Assert.AreEqual (1, span.LongitudeDegrees);
			Assert.IsTrue (span.Radius.Kilometers > 54 && span.Radius.Kilometers < 56);
		}
 public MapRenderer2(MapSpan region)
     : base(region)
 {
     MessagingCenter.Subscribe<Location>(this, MESSAGE_ON_INFO_WINDOW_CLICKED, (loc) =>
     {
         if (OnInfoWindowClicked != null)
             OnInfoWindowClicked(loc);
     });
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TreeWatch.FieldMap"/> class.
        /// </summary>
        /// <param name="region">The actual position inside the map.</param>
        public FieldMap(MapSpan region)
            : base(region)
        {
            this.Fields = new ObservableCollection<Field>();
            this.overlayColor = Color.Transparent;
            this.boundaryColor = Color.FromHex("#ff8400");

            this.StyleId = "FieldMapView";
        }
Ejemplo n.º 8
0
	    static void HitungKoordinat(MapSpan daerah)
	    {
	        var pusat = daerah.Center;
	        var paruhTinggi = daerah.LatitudeDegrees/2;
	        var paruhSamping = daerah.LongitudeDegrees/2;

	        var kiri = pusat.Longitude - paruhSamping;
	        var kanan = pusat.Longitude + paruhSamping;
	        var atas = pusat.Latitude + paruhTinggi;
	        var bawah = pusat.Latitude - paruhTinggi;

	        if (kiri < -180) kiri = 180 + (180 + kiri);
	        if (kanan > 180) kanan = (kanan - 180) - 180;
	    }
Ejemplo n.º 9
0
        public TripPage(MbtaRoutePrediction selectedRoute, MbtaPrediction singlePrediction, Geolocator.Plugin.Abstractions.Position currentLocation)
        {
            this.selectedRoute = selectedRoute;
            this.singlePrediction = singlePrediction;
            this.currentLocation = currentLocation;

            var mapPosition = new Position (currentLocation.Latitude, currentLocation.Longitude);
            currentSpan = MapSpan.FromCenterAndRadius(mapPosition, Distance.FromMiles(0.3));
            map = new Map (currentSpan) {
                IsShowingUser = true,
                HeightRequest = 100,
                VerticalOptions = LayoutOptions.FillAndExpand
            };
            var stack = new StackLayout { Spacing = 0 };
            stack.Children.Add(map);
            Content = stack;

            FetchPredictions ();
        }
Ejemplo n.º 10
0
        ///<inheritdoc/>
        public async Task<IEnumerable<IPlaceResult>> GetPredictions(string query, MapSpan bounds)
        {
            if (this._apiClient == null || !this._apiClient.IsConnected) this.Connect();

            List<IPlaceResult> result = new List<IPlaceResult>();

            double mDistanceInMeters = bounds.Radius.Meters;
            
            double latRadian = bounds.LatitudeDegrees;

            double degLatKm = 110.574235;
            double degLongKm = 110.572833 * Math.Cos(latRadian);
            double deltaLat = mDistanceInMeters / 1000.0 / degLatKm;
            double deltaLong = mDistanceInMeters / 1000.0 / degLongKm;

            double minLat = bounds.Center.Latitude - deltaLat;
            double minLong = bounds.Center.Longitude - deltaLong;
            double maxLat = bounds.Center.Latitude + deltaLat;
            double maxLong = bounds.Center.Longitude + deltaLong;

            if (this._buffer != null)
            {
                this._buffer.Dispose();
                this._buffer = null;
            }

            this._buffer = await PlacesClass.GeoDataApi.GetAutocompletePredictionsAsync(
                this._apiClient, 
                query, 
                new LatLngBounds(new LatLng(minLat, minLong), new LatLng(maxLat, maxLong)), 
                null);
            
            if (this._buffer != null)
            {
                result.AddRange(this._buffer.Select(i => 
                    new TKNativeAndroidPlaceResult
                    {
                        Description = i.Description,
                        PlaceId = i.PlaceId,
                    }));
            }
            return result;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// In response to this forum question http://forums.xamarin.com/discussion/22493/maps-visibleregion-bounds
        /// Useful if you need to send the bounds to a web service or otherwise calculate what
        /// pins might need to be drawn inside the currently visible viewport.
        /// </summary>
        static void CalculateBoundingCoordinates(MapSpan region)
        {
            // WARNING: I haven't tested the correctness of this exhaustively!
            var center = region.Center;
            var halfheightDegrees = region.LatitudeDegrees / 2;
            var halfwidthDegrees = region.LongitudeDegrees / 2;

            var left = center.Longitude - halfwidthDegrees;
            var right = center.Longitude + halfwidthDegrees;
            var top = center.Latitude + halfheightDegrees;
            var bottom = center.Latitude - halfheightDegrees;

            // Adjust for Internation Date Line (+/- 180 degrees longitude)
            if (left < -180) left = 180 + (180 + left);
            if (right > 180) right = (right - 180) - 180;
            // I don't wrap around north or south; I don't think the map control allows this anyway

            Debug.WriteLine ("Bounding box:");
            Debug.WriteLine ("                    " + top);
            Debug.WriteLine ("  " + left + "                " + right);
            Debug.WriteLine ("                    " + bottom);
        }
        //  private readonly INavigationService _navigationService;


        public PinPage()
        {
            map = new Map
            {
                IsShowingUser   = true,
                HeightRequest   = 100,
                WidthRequest    = 960,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                 new Position(33.812092, -117.918976), Distance.FromMiles(3)));



            var position = new Position(33.812092, -117.918976); // Latitude, Longitude
            var pin      = new Pin
            {
                Type     = PinType.Place,
                Position = position,
                Label    = "DisneyLand",
                Address  = "03815547-55e6-4717-a7bd-71b587e5fbc9"
                           //Id= "03815547-55e6-4717-a7bd-71b587e5fbc9"
            };

            map.Pins.Add(new Pin
            {
                Type     = PinType.Place,
                Position = new Position(34.050750, -118.081010),
                Label    = "Southern California Edison",
                Address  = "Rosemead, CA"
            });
            map.Pins.Add(new Pin
            {
                Type     = PinType.Place,
                Position = new Position(34.092808, -118.328659),
                Label    = "Hollywood",
                Address  = "Hollywood California"
            });
            map.Pins.Add(pin);

            pin.Clicked += (object sender, EventArgs e) =>
            {
                var p = sender as Pin;

                Outage outage = new Outage()
                {
                    Id             = p.Address,
                    OutageResolved = true
                };


                UpdateOutage(outage);
            };


            // create buttons
            var morePins = new Button {
                Text = "Add more pins"
            };

            morePins.Clicked += (sender, e) => {
                map.Pins.Add(new Pin
                {
                    Type     = PinType.Place,
                    Position = new Position(36.9641949, -122.0177232),
                    Label    = "Boardwalk",
                    Address  = "custom detail info"
                });
                map.Pins.Add(new Pin
                {
                    Type     = PinType.Place,
                    Position = new Position(36.9571571, -122.0173544),
                    Label    = "Wharf",
                    Address  = "custom detail info"
                });
                map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                     new Position(36.9628066, -122.0194722), Distance.FromMiles(1.5)));
            };
            var reLocate = new Button {
                Text = "Re-center"
            };

            reLocate.Clicked += (sender, e) => {
                map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                     new Position(36.9628066, -122.0194722), Distance.FromMiles(3)));
            };
            var buttons = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    morePins, reLocate
                }
            };

            // put the page together
            Content = new StackLayout
            {
                Spacing  = 0,
                Children =
                {
                    map,
                    buttons
                }
            };
        }
Ejemplo n.º 13
0
		void MoveToRegion (MapSpan span, bool animate)
		{
			var map = NativeMap;
			if (map == null)
				return;

			span = span.ClampLatitude (85, -85);
			var ne = new LatLng (span.Center.Latitude + span.LatitudeDegrees / 2, span.Center.Longitude + span.LongitudeDegrees / 2);
			var sw = new LatLng (span.Center.Latitude - span.LatitudeDegrees / 2, span.Center.Longitude - span.LongitudeDegrees / 2);
			var update = CameraUpdateFactory.NewLatLngBounds (new LatLngBounds (sw, ne), 0);
	
			try {
				if (animate)
					map.AnimateCamera (update);
				else
					map.MoveCamera (update);
			} catch (IllegalStateException exc) {
				System.Diagnostics.Debug.WriteLine ("MoveToRegion exception: " + exc);
			}
		}
        public async void LoadLocationAsync(string url)
        {
            var location = await dataService.GetLocationAsync(url);

            viewModel.Location = location;


            if (!viewModel.Location.Latitude.Equals(0) && !viewModel.Location.Longitude.Equals(0))
            {
                try
                {
                    var position = new Position(viewModel.Location.Latitude, viewModel.Location.Longitude);

                    var map = new Map(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(0.1)))
                    {
                        //IsShowingUser = true,
                        HeightRequest   = 100,
                        WidthRequest    = 960,
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        MapType         = MapType.Street
                    };

                    var pin = new Pin
                    {
                        Address  = viewModel.Location.FormattedAddress,
                        Label    = viewModel.Location.Name,
                        Type     = PinType.SearchResult,
                        Position = position
                    };

                    map.Pins.Add(pin);

                    MapView.Children.Add(map);

                    // Add to contact list so the directions link is added with
                    // the rest of the contact entries.
                    viewModel.Location.contacts.Insert(0, new Contact
                    {
                        ContactData = viewModel.Location.FormattedAddress,
                        ContactType = "Directions",
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Service List Grid
            try
            {
                if (viewModel.Location.ServiceTypes != null)
                {
                    foreach (string service in viewModel.Location.ServiceTypes)
                    {
                        var column = serviceItemCount % 2 == 0 ? 0 : 1;

                        var label = new Label();
                        label.Text = "•  " + service;
                        ServiceGrid.Children.Add(label, column, (int)Math.Floor((double)serviceItemCount / 2));

                        serviceItemCount++;
                    }
                }

                if (viewModel.Location.Categories != null && viewModel.Location.Categories.Count > 0)
                {
                    // If new values are loaded, hide the old grid.
                    ServiceGrid.IsVisible   = false;
                    ServicesLabel.IsVisible = false;

                    CategoriesLabel.IsVisible = true;
                    CategoriesGrid.IsVisible  = true;

                    foreach (var category in viewModel.Location.Categories)
                    {
                        var column = categoryItemCount % 2 == 0 ? 0 : 1;

                        var label = new Label();
                        label.Text = "•  " + category.ServiceType;
                        CategoriesGrid.Children.Add(label, column, (int)Math.Floor((double)categoryItemCount / 2));

                        categoryItemCount++;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            // Address
            AddressLabel.Text = viewModel.Location.FormattedAddress;

            if (viewModel.Location.contacts != null)
            {
                try
                {
                    // Contact List
                    foreach (var contact in viewModel.Location.contacts)
                    {
                        var description = new Label {
                            FontSize = 17, TextColor = Color.FromHex("813C27"), Text = contact.ContactData
                        };
                        var contactType = contact.ContactType;
                        var imageIcon   = "call.png";

                        if (contactType == "Twitter")
                        {
                            imageIcon = "twitter.png";

                            var linkUrl = contact.ContactData;

                            if (!linkUrl.StartsWith("http", StringComparison.Ordinal))
                            {
                                var username = contact.ContactData.Replace("@", "");
                                linkUrl = "https://twitter.com/" + username;
                            }

                            description.GestureRecognizers.Add(new TapGestureRecognizer
                            {
                                Command = new Command(() => {
                                    try
                                    {
                                        Device.OpenUri(new Uri(linkUrl));
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                })
                            });
                        }


                        if (contactType == "Email")
                        {
                            imageIcon = "email.png";

                            description.GestureRecognizers.Add(new TapGestureRecognizer
                            {
                                Command = new Command(() => {
                                    try
                                    {
                                        Device.OpenUri(new Uri("mailto:" + contact.ContactData));
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                })
                            });
                        }


                        if (contactType == "Web Page")
                        {
                            imageIcon = "link.png";

                            var linkUrl = contact.ContactData;

                            if (!linkUrl.StartsWith("http", StringComparison.Ordinal))
                            {
                                linkUrl = "http://" + contact.ContactData;
                            }

                            description.GestureRecognizers.Add(new TapGestureRecognizer
                            {
                                Command = new Command(() => {
                                    try
                                    {
                                        Device.OpenUri(new Uri(linkUrl));
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                })
                            });
                        }

                        // This "contact type" is manually added when a map
                        // is rendered. The ContactData is a string with the
                        // location address
                        if (contactType == "Directions")
                        {
                            imageIcon = "directions.png";

                            var address = contact.ContactData;
                            description.Text = "Open in maps";

                            description.GestureRecognizers.Add(new TapGestureRecognizer
                            {
                                Command = new Command(() => {
                                    try
                                    {
                                        switch (Device.RuntimePlatform)
                                        {
                                        case Device.iOS:
                                            Device.OpenUri(
                                                new Uri(string.Format("http://maps.apple.com/?q={0}", WebUtility.UrlEncode(address))));
                                            break;

                                        case Device.Android:
                                            Device.OpenUri(
                                                new Uri(string.Format("geo:0,0?q={0}", WebUtility.UrlEncode(address))));
                                            break;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                })
                            });
                        }

                        if (contactType == "Phone")
                        {
                            imageIcon = "call.png";

                            description.GestureRecognizers.Add(new TapGestureRecognizer
                            {
                                Command = new Command(() => {
                                    try
                                    {
                                        Device.OpenUri(new Uri("tel:" + contact.ContactData));
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                })
                            });
                        }


                        // Facebook is a weird one. These two actually need to combine
                        // to make one label/link
                        if (contactType == "Facebook Name")
                        {
                            continue;
                        }

                        if (contactType == "Facebook URL")
                        {
                            imageIcon = "facebook.png";

                            var facebookNameEntry = viewModel.Location.contacts.Where(c => c.ContactType == "Facebook Name");
                            description.Text = facebookNameEntry.Any() ? facebookNameEntry.First().ContactData : location.Name;
                            var linkUrl = contact.ContactData;

                            try
                            {
                                description.GestureRecognizers.Add(new TapGestureRecognizer
                                {
                                    Command = new Command(() => {
                                        try
                                        {
                                            Device.OpenUri(new Uri(linkUrl));
                                        }
                                        catch (Exception ex)
                                        {
                                            Console.WriteLine(ex.Message);
                                        }
                                    })
                                });
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }


                        var contentStackLayout = new StackLayout {
                            Padding = new Thickness {
                                Left = 20, Top = 20
                            }
                        };
                        var lineStackLayout = new StackLayout {
                            Padding = new Thickness {
                                Left = 20, Right = 20
                            }, Margin = new Thickness {
                                Top = 10
                            }
                        };
                        var boxView = new BoxView
                        {
                            BackgroundColor   = Color.FromHex("DADADA"),
                            HeightRequest     = 2,
                            VerticalOptions   = LayoutOptions.Start,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            Margin            = 0
                        };

                        lineStackLayout.Children.Add(boxView);

                        var grid = new Grid();
                        grid.ColumnDefinitions.Add(new ColumnDefinition {
                            Width = 30
                        });
                        grid.ColumnDefinitions.Add(new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        });

                        var image = new Image {
                            Source = imageIcon
                        };
                        var textStackLayout = new StackLayout {
                            Margin = new Thickness {
                                Left = 10
                            }
                        };
                        var title = new Label {
                            FontSize = 16, FontAttributes = FontAttributes.Bold, Text = contact.ContactType
                        };


                        textStackLayout.Children.Add(title);
                        textStackLayout.Children.Add(description);

                        grid.Children.Add(image, 0, 0);
                        grid.Children.Add(textStackLayout, 1, 0);

                        contentStackLayout.Children.Add(grid);

                        ContactList.Children.Add(contentStackLayout);
                        ContactList.Children.Add(lineStackLayout);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
        }
Ejemplo n.º 15
0
        public PinPage()
        {
            map = new Map
            {
                IsShowingUser   = true,
                HeightRequest   = 100,
                WidthRequest    = 960,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                 new Position(36.9628066, -122.0194722), Distance.FromMiles(3))); // Santa Cruz golf course

            var position = new Position(36.9628066, -122.0194722);                                // Latitude, Longitude
            var pin      = new Pin
            {
                Type     = PinType.Place,
                Position = position,
                Label    = "Santa Cruz",
                Address  = "custom detail info"
            };

            map.Pins.Add(pin);


            // create buttons
            var morePins = new Button {
                Text = "加入更多 位置標示"
            };

            morePins.Clicked += (sender, e) => {
                map.Pins.Add(new Pin
                {
                    Position = new Position(36.9641949, -122.0177232),
                    Label    = "Boardwalk"
                });
                map.Pins.Add(new Pin
                {
                    Position = new Position(36.9571571, -122.0173544),
                    Label    = "Wharf"
                });
                map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                     new Position(36.9628066, -122.0194722), Distance.FromMiles(1.5)));
            };
            var reLocate = new Button {
                Text = "重新定位"
            };

            reLocate.Clicked += (sender, e) => {
                map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                     new Position(36.9628066, -122.0194722), Distance.FromMiles(3)));
            };
            var buttons = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    morePins, reLocate
                }
            };

            // put the page together
            Content = new StackLayout
            {
                Spacing  = 0,
                Children =
                {
                    map,
                    buttons
                }
            };
        }
Ejemplo n.º 16
0
        public MapPage()
        {
            map = new CustomMap
            {
                IsShowingUser   = true,
                HeightRequest   = 100,
                WidthRequest    = 960,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            map.Shapes.Add(new List <Position>());
            map.Shapes[0].Add(new Position(33.5, -101.8));
            map.Shapes[0].Add(new Position(33.5, -101.9));
            map.Shapes[0].Add(new Position(33.6, -101.9));
            map.Shapes[0].Add(new Position(33.6, -101.8));

            map.Shapes.Add(new List <Position>());
            map.Shapes[1].Add(new Position(43.5, -101.8));
            map.Shapes[1].Add(new Position(43.5, -101.9));
            map.Shapes[1].Add(new Position(43.6, -101.9));
            map.Shapes[1].Add(new Position(43.6, -101.8));

            map.Shapes.Add(new List <Position>());
            map.Shapes[2].Add(new Position(33.5, -111.8));
            map.Shapes[2].Add(new Position(33.5, -111.9));
            map.Shapes[2].Add(new Position(33.6, -111.9));
            map.Shapes[2].Add(new Position(33.6, -111.8));

            // You can use MapSpan.FromCenterAndRadius

            map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(33.57, -101.85), Distance.FromMiles(1000.0)));

            // map terrain buttons
            var Street = new Button
            {
                Text = "Street"
            };
            var Satellite = new Button
            {
                Text = "Satellite"
            };

            Street.Clicked    += HandleClicked;
            Satellite.Clicked += HandleClicked;

            var segments = new StackLayout
            {
                Spacing           = 30,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Orientation       = StackOrientation.Horizontal,
                Children          =
                {
                    Street,
                    Satellite
                }
            };
            // create pin
            var pin = new Pin
            {
                Position = new Position(30.57, -99.85),
                Label    = "Texas"
            };

            pin.Clicked += PinSelect;
            map.Pins.Add(pin);

            // Assemble the page
            var stack = new StackLayout
            {
                Spacing = 0
            };

            stack.Children.Add(map);
            stack.Children.Add(segments);
            //       stack.Children.Add(pin);
            Content = stack;
        }
Ejemplo n.º 17
0
 void MoveMapToPosition(Position position)
 {
     map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1.2)));
 }
Ejemplo n.º 18
0
		private void HandleCenterGamefield()
		{
			WF.Player.Core.CoordBounds bounds;

			if (App.Game != null)
			{
				// Map is viewed inside the game
				bounds = App.Game.Bounds;

				if (bounds == null)
				{
					return;
				}

				visibleRegion = new MapSpan(new Xamarin.Forms.Maps.Position(bounds.Center.Latitude, bounds.Center.Longitude), 
					Math.Abs(bounds.Top - bounds.Bottom) * 1.1, 
					Math.Abs(bounds.Right - bounds.Left) * 1.1);
			}
			else
			{
				// Map is viewed outside the game, so show StartingLocation
				visibleRegion = MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(StartingLocation.Latitude, StartingLocation.Longitude), Distance.FromMeters(1000));
			}

			map.MoveToRegion(visibleRegion);
		}
Ejemplo n.º 19
0
 public static Position TopLeft(this MapSpan self)
 {
     return(new SKMapSpan(self).TopLeft.ToPosition());
 }
Ejemplo n.º 20
0
        private async void btn32_Clicked(object sender, EventArgs e)
        {
            Mapa1.IsShowingUser      = true;
            MyStackLayout.IsVisible  = false;
            MyStackLayout1.IsVisible = false;
            MyStackLayout2.IsVisible = false;
            MyStackLayout3.IsVisible = false;
            MyStackLayout4.IsVisible = false;
            MyStackLayout5.IsVisible = false;

            btn32.TextColor       = Color.DarkRed;
            btn32.BackgroundColor = Color.White;
            btn32.FontAttributes  = FontAttributes.Bold;
            //   Stack2.IsVisible = false;

            btn2.BackgroundColor = Color.DarkRed;
            btn2.TextColor       = Color.White;
            btn3.BackgroundColor = Color.DarkRed;
            btn3.TextColor       = Color.White;
            var listApartmana = await _apartmani.Get <IList <Model.Apartmani> >(null);

            var listaAtrakcija = await _atrakcije.Get <IList <Model.Atrakcije> >(null);

            var listaKafica = await _kafici.Get <IList <Model.Kafici> >(null);

            var listaHotela = await _hoteli.Get <IList <Model.Hoteli> >(null);

            var listaRestorana = await _restorani.Get <IList <Model.Restorani> >(null);

            var listaNk = await _nocniklubovi.Get <IList <Model.Nightclubs> >(null);

            StackMapa.IsVisible = true;
            var request = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(10));

            cts = new CancellationTokenSource();
            tcs = new TaskCompletionSource <PermissionStatus>();
            var location = await Geolocation.GetLocationAsync(request, cts.Token);

            var      client   = new System.Net.Http.HttpClient();
            Position position = new Position(location.Latitude, location.Longitude);

            MapSpan mapSpan = MapSpan.FromCenterAndRadius(position, Distance.FromKilometers(0.444));

            Mapa1.MoveToRegion(mapSpan);
            if (APIService.Atraction)
            {
                foreach (var item in listaAtrakcija)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response


                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Apartments)
            {
                foreach (var item in listApartmana)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Food)
            {
                foreach (var item in listaRestorana)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Nightclubs)
            {
                foreach (var item in listaNk)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Coffeeshops)
            {
                foreach (var item in listaKafica)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
        }
Ejemplo n.º 21
0
        public JBLaurelMap()
        {
            Title           = "JailBreak Laurel";
            BackgroundColor = Color.White;

            var lense = new Image()
            {
                Source = new FileImageSource()
                {
                    File = "maplense.png"
                },
                Aspect           = Aspect.AspectFill,
                IsOpaque         = true,
                InputTransparent = true
            };

            var map = new Map(
                MapSpan.FromCenterAndRadius(
                    new Position(39.124164, -76.823165), Distance.FromMiles(0.3)))
            {
                IsShowingUser = true,
            };

            var jbLaurelpin = new Pin {
                Type     = PinType.Place,
                Position = new Position(39.124164, -76.823165),
                Label    = "JailBreak Laurel Brewery",
                Address  = "9445 Washington Blvd N, STE F, Laurel, MD 20723"
            };


            map.Pins.Add(jbLaurelpin);


            jbLaurelpin.Clicked += (sender, e) => {
                //DisplayAlert("Go Directly to Jail-break", "Will Launch your Mapp App", "Ok");
                Device.OpenUri(new Uri("http://maps.apple.com/?daddr=39.124164,-76.823165"));
            };

            var stack = new StackLayout()
            {
                Padding  = new Thickness(10),
                Children =
                {
                    new Label()
                    {
                        FontAttributes = FontAttributes.Bold,
                        Text           = "Best Mode of Travel:",
                        TextColor      = Color.FromHex("852F29"),
                    },
                    new Label()
                    {
                        Text     = "Click the Navigation Pin to Open your Map App for Navigation or...Coming from I-95, take Rt. 32 to US 1, head South pass Carmax, we are on the Left",
                        FontSize = 14,
                    },
                    new Label()
                    {
                        FontAttributes = FontAttributes.Bold,
                        Text           = "Beer Tours Available:",
                        TextColor      = Color.FromHex("852F29"),
                    },
                    new Label()
                    {
                        Text     = "Wed. - Sat. 3:00 PM to 9:00 PM",
                        FontSize = 14
                    },
                }
            };

            var orderonline = new StackLayout()
            {
                BackgroundColor = Color.FromHex("E6A93D"),
                Children        =
                {
                    new Label()
                    {
                        Text              = "Come and Plan your Escape!",
                        FontSize          = 22,
                        FontAttributes    = FontAttributes.Bold,
                        TextColor         = Color.White,
                        HorizontalOptions = LayoutOptions.Center,
                        VerticalOptions   = LayoutOptions.CenterAndExpand
                    },
                }
            };



            RelativeLayout relativeLayout = new RelativeLayout()
            {
                HeightRequest = 100,
            };

            relativeLayout.Children.Add(
                map,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            }),
                Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            })
                );

            relativeLayout.Children.Add(
                lense,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            }),
                Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            })
                );

            relativeLayout.Children.Add(
                stack,
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => {
                return(parent.Width - 10);
            }),
                Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            }),
                Constraint.RelativeToParent((parent) => {
                return(parent.Height - (parent.Width + 50));
            })
                );

            relativeLayout.Children.Add(
                orderonline,
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => {
                return(parent.Height - 50);
            }),
                Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            }),
                Constraint.RelativeToParent((parent) => {
                return(50);
            })
                );

            this.Content = relativeLayout;
        }
Ejemplo n.º 22
0
 public static bool Crosses180thMeridianLeft(this MapSpan self)
 {
     return(new SKMapSpan(self).Crosses180thMeridianLeft());
 }
Ejemplo n.º 23
0
 public static MapSpan WrapIfRequired(this MapSpan self)
 {
     return(new SKMapSpan(self).WrapIfRequired().ToMapSpan());
 }
Ejemplo n.º 24
0
 public static Position BottomRight(this MapSpan self)
 {
     return(new SKMapSpan(self).BottomRight.ToPosition());
 }
Ejemplo n.º 25
0
 public new void MoveToRegion(MapSpan span)
 {
     Region = span;
     MessagingCenter.Send<Map, MapMessage>(this, MapMessage.Message, new ZoomMessage(this, span));
 }
Ejemplo n.º 26
0
		public ExtendedMap(MapSpan span) : base(span)
		{
			mapOrientation = MapOrientation.NorthUp;
		}
Ejemplo n.º 27
0
        void AddPins(object sender, EventArgs e)                                 //function adds all the pins to the map
        {
            Dictionary <string, Pin> pickerplaces = new Dictionary <string, Pin> //treating pins as a Dictionary of strings in order to access pin locations for picker
            {
                { "Winco", new Pin                                               //declaring pins , relevant bc this is where I go to get food
                  {
                      Type     = PinType.Place,
                      Address  = "555 Grand Ave, San Marcos, CA 92078, United States",
                      Label    = "Winco Foods",
                      Position = new Position(33.135040, -117.176830)
                  }
                  //HomeMap.Pins.Add(Pin)
                },
                { "24 Hour Fitness", new Pin //declaring pins, relevant bc I (used to) love going to the gym
                  {
                      Type     = PinType.Place,
                      Address  = "641 S Rancho Santa Fe Rd, San Marcos, CA 92069, United States",
                      Label    = "24 Hour Fitness",
                      Position = new Position(33.133180, -117.206660)
                  } },

                //HomeMap.Pins.Add(pin2);

                { "Mom's House", new Pin //declaring pins, relevant bc my dog is there and so are my parents
                  {
                      Type     = PinType.Place,
                      Address  = "1943 C Ave, National City, CA 91950, United States",
                      Label    = "Mom's House",
                      Position = new Position(32.666570, -117.099840)
                  } },

                //HomeMap.Pins.Add(pin3);

                { "Self Quarantine aka home", new Pin //declaring pin, relevant bc it's my house
                  {
                      Type     = PinType.Place,
                      Address  = "353 W San Marcos Blvd, San Marcos, CA 92069, United States",
                      Label    = "Self Quarantine aka home",
                      Position = new Position(33.138550, -117.168890)
                  } },

                { "Discovery Lake", new Pin //declaring pin, relevant to me bc I (used to) go hiking there a lot
                  {
                      Type     = PinType.Place,
                      Address  = "3650 Foxhall Dr, San Marcos, CA 92078, United States",
                      Label    = "Discovery Lake",
                      Position = new Position(33.126600, -117.177300)
                  } },
            };

            foreach (Pin pin in pickerplaces.Values) //adding all pins to the map
            {
                HomeMap.Pins.Add(pin);
            }
            ;
            // HomeMap.Pins.Add(pin4)

            Picker.SelectedIndexChanged += (button, args) =>                                             //if the selected instance of the picker is changed
            {
                string location    = Picker.Items[Picker.SelectedIndex];                                 //location is based off of the picker index selected
                var    NewLocation = pickerplaces[location].Position;                                    //the new location of the map will be based on the pin position of the picker index selected
                HomeMap.MoveToRegion(MapSpan.FromCenterAndRadius(NewLocation, Distance.FromMiles(.50))); //moves to region based on picker
            };
        }
Ejemplo n.º 28
0
 public MoveToRegionMessage(MapSpan mapSpan, bool animate = true)
 {
     this.Span    = mapSpan;
     this.Animate = animate;
 }
Ejemplo n.º 29
0
        //Request a Route using Google Directions API
        async private void requestRoute(Position startLocation, Position endLocation, Position waypoint1, Position waypoint2, Position waypoint3)
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                Console.Out.WriteLine("Connection Valid");
            }
            else
            {
                Console.Out.WriteLine("Connection Invalid");
            }
            Console.Out.WriteLine("Try Requesting");
            string apiKey     = "AIzaSyBj3FmgND9IRoLFfh25eiE2x6Hg37uzDg4";
            string requesturl = "https://maps.googleapis.com/maps/api/directions/json?" + "mode=walking" + "&units=metric" + "&avoid=ferries"
                                + "&origin=" + startLocation.Latitude.ToString() + "," + startLocation.Longitude.ToString()
                                + "&destination=" + endLocation.Latitude.ToString() + "," + endLocation.Longitude.ToString()
                                + "&waypoints=optimize:true|" + waypoint1.Latitude.ToString() + "," + waypoint1.Longitude.ToString() + "|" + waypoint2.Latitude.ToString() + "," + waypoint2.Longitude.ToString() + "|" + waypoint3.Latitude.ToString() + "," + waypoint3.Longitude.ToString()
                                + "&key=" + apiKey;

            //Test for exceptions
            string strException = "-1";

            string strJSONDirectionResponse = await FnHttpRequest(requesturl);

            if (strJSONDirectionResponse == strException)
            {
                Console.Out.WriteLine("Error Returned");
                return;
            }

            //Convert Json to a class
            var objRoutes = JsonConvert.DeserializeObject <googledirectionclass>(strJSONDirectionResponse);

            // Check for error return case - Return to options screen if error returned
            if (objRoutes.status != "OK")
            {
                await DisplayAlert("Alert", "Problem with Directions Request: " + objRoutes.status, "OK");

                //Go back to options screen
                await Navigation.PopAsync();

                return;
            }
            else
            {
                //Decode The Returned points
                string encodedPoints    = objRoutes.routes[0].overview_polyline.points;
                var    lstDecodedPoints = FnDecodePolylinePoints(encodedPoints);

                Xamarin.Forms.GoogleMaps.Polyline polylineoption = new Xamarin.Forms.GoogleMaps.Polyline();

                polylineoption.StrokeWidth = 6f;
                polylineoption.StrokeColor = Color.White;

                double[] latList = new double[lstDecodedPoints.Count];
                double[] lngList = new double[lstDecodedPoints.Count];

                for (int i = 0; i < lstDecodedPoints.Count; i++)
                {
                    polylineoption.Positions.Add(lstDecodedPoints[i]);
                    latList[i] = lstDecodedPoints[i].Latitude;
                    lngList[i] = lstDecodedPoints[i].Longitude;
                }

                double latCentre, lngCentre;
                latCentre = (latList.Max() + latList.Min()) / 2;
                lngCentre = (lngList.Max() + lngList.Min()) / 2;
                Position routeCentrePos = new Position(latCentre, lngCentre);

                //Add polyline to map
                map.Polylines.Add(polylineoption);
                MapSpan routeSpan = new MapSpan(routeCentrePos, 0.02, 0.02);
                map.MoveToRegion(routeSpan);
            }


            //--TASKS--

            //Request String
            WebClient webclient;

            async Task <string> FnHttpRequest(string strUri)
            {
                webclient = new WebClient();
                string strResultData = "";

                try
                {
                    strResultData = await webclient.DownloadStringTaskAsync(new Uri(strUri));
                }
                catch (Exception ex)
                {
                    strResultData = strException;
                    Console.Out.WriteLine("Exception: " + ex);
                }
                finally
                {
                    //Clear resources used
                    if (webclient != null)
                    {
                        webclient.Dispose();
                        webclient = null;
                    }
                }

                return(strResultData);
            }

            //Function to decode encoded points
            List <Position> FnDecodePolylinePoints(string Points)
            {
                if (string.IsNullOrEmpty(Points))
                {
                    return(null);
                }
                var poly = new List <Position>();

                char[] polylinechars = Points.ToCharArray();
                int    ind           = 0;

                int currentLat = 0;
                int currentLng = 0;
                int next5bits;
                int sum;
                int shifter;

                while (ind < polylinechars.Length)
                {
                    //Calculate next latitude
                    sum     = 0;
                    shifter = 0;
                    do
                    {
                        next5bits = (int)polylinechars[ind++] - 63;
                        sum      |= (next5bits & 31) << shifter;
                        shifter  += 5;
                    }while (next5bits >= 32 && ind < polylinechars.Length);

                    if (ind >= polylinechars.Length)
                    {
                        break;
                    }

                    currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);

                    //calculate next longitude
                    sum     = 0;
                    shifter = 0;
                    do
                    {
                        next5bits = (int)polylinechars[ind++] - 63;
                        sum      |= (next5bits & 31) << shifter;
                        shifter  += 5;
                    }while (next5bits >= 32 && ind < polylinechars.Length);

                    if (ind >= polylinechars.Length && next5bits >= 32)
                    {
                        break;
                    }

                    currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);

                    Position p = new Position(Convert.ToDouble(currentLat) / 100000.0, Convert.ToDouble(currentLng) / 100000.0);
                    poly.Add(p);
                }
                return(poly);
            }
        }
Ejemplo n.º 30
0
        //Constructor
        public MapPage(double distance)
        {
            double setDistance = distance;

            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

            //Reference the map component
            map = (Map)MyMap;

            //Customize Map
            map.MapType          = MapType.Street;
            map.IsTrafficEnabled = false;
            var    assembly = IntrospectionExtensions.GetTypeInfo(typeof(MapStyleClass)).Assembly;
            Stream stream   = assembly.GetManifestResourceStream("jogr.CustomMap.json");

            if (stream != null)
            {
                string text = "";
                using (var reader = new StreamReader(stream))
                {
                    text         = reader.ReadToEnd();
                    map.MapStyle = MapStyle.FromJson(text);
                }
            }
            else
            {
                Console.Out.WriteLine("Style stream was empty");
            }

            //Create Location Pin
            myLocation = new Pin
            {
                Type  = PinType.Place,
                Label = "myLocation",
                Icon  = BitmapDescriptorFactory.DefaultMarker(Color.Red)
            };

            displayRoute();

            //Generate a route based on current location
            async Task displayRoute()
            {
                //Get the users current location
                Plugin.Geolocator.Abstractions.Position myGeoPos = null;
                try
                {
                    var locator = CrossGeolocator.Current;
                    locator.DesiredAccuracy = 100;
                    myGeoPos = await locator.GetPositionAsync(TimeSpan.FromSeconds(1));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("There was an error: " + ex);
                }

                Position myPos = new Position(myGeoPos.Latitude, myGeoPos.Longitude);

                //Display a pin at users location
                myLocation.Position = myPos;
                map.Pins.Add(myLocation);

                //Create Timer for updating users location
                locationTimer           = new System.Timers.Timer(500);
                locationTimer.Elapsed  += UpdateUserLocation;
                locationTimer.Enabled   = true;
                locationTimer.AutoReset = true;

                //Zoom the map into the users location
                MapSpan mySpan = new MapSpan(myPos, 5, 5);

                map.MoveToRegion(mySpan);

                // Set distance between waypoints based on passed distance option
                double distanceMetres  = setDistance * 1000;
                double quarterDistance = distanceMetres / 4;

                //Randomize route direction
                Random random = new Random(DateTime.UtcNow.Millisecond);
                int    directionRandomizer = random.Next(0, 4);

                Position waypoint1 = ConvertDistToLatLng(myPos, directionRandomizer % 4, quarterDistance);
                Position waypoint2 = ConvertDistToLatLng(waypoint1, (directionRandomizer + 1) % 4, quarterDistance);
                Position waypoint3 = ConvertDistToLatLng(waypoint2, (directionRandomizer + 2) % 4, quarterDistance);

                //Request directions using waypoints
                requestRoute(myPos, myPos, waypoint1, waypoint2, waypoint3);
            }
        }
Ejemplo n.º 31
0
        public async void UpdateMapCenterAsync()
        {
            var position = await _geolocationService.GetCurrentPosition();

            this.Map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1)));
        }
Ejemplo n.º 32
0
 async void GetLocation()
 {
     Map.MoveToRegion(MapSpan.FromCenterAndRadius(START_POINT, START_DISTANCE));
 }
Ejemplo n.º 33
0
 void HomeClicked(object sender, EventArgs e)
 {
     Map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(41.890202, 12.492049), Distance.FromMiles(0.5)));
 }
        public RomanianMapRestaurants()
        {
            InitializeComponent();
            try
            {
                var map = new Map(MapSpan.FromCenterAndRadius(
                                      new Position(44.4268, 26.1025),
                                      Distance.FromMiles(1.5)))
                {
                    IsShowingUser   = true,
                    VerticalOptions = LayoutOptions.FillAndExpand
                };


                var position1 = new Position(44.4320389, 26.0893723);
                var position2 = new Position(44.4168926, 26.1146395);
                var position3 = new Position(44.437958, 26.123317);
                var position4 = new Position(44.4710441, 26.0907489);
                var position5 = new Position(44.4320201, 26.0959384);
                var position6 = new Position(44.4305753, 26.1028397);

                var pin1 = new Pin
                {
                    Type     = PinType.Place,
                    Position = position1,
                    Label    = "Hanu' Berarilor Casa Soare",
                    Address  = "Strada Poenaru Bordea 2",
                };

                var pin2 = new Pin
                {
                    Type     = PinType.Place,
                    Position = position2,
                    Label    = "Taverna Racilor",
                    Address  = "Strada Nerva Traian 4",
                };

                var pin3 = new Pin
                {
                    Type     = PinType.Place,
                    Position = position3,
                    Label    = "Taverna La Zavat",
                    Address  = "Strada Popa Nan 16",
                };

                var pin4 = new Pin
                {
                    Type     = PinType.Place,
                    Position = position4,
                    Label    = "Restaurant Pescarus",
                    Address  = "Address: Aviatorilor Bld., No. 1",
                };

                var pin5 = new Pin
                {
                    Type     = PinType.Place,
                    Position = position5,
                    Label    = "Caru' cu Bere",
                    Address  = "Strada Stavropoleos 5",
                };

                var pin6 = new Pin
                {
                    Type     = PinType.Place,
                    Position = position6,
                    Label    = "Lacrimi si sfinti",
                    Address  = "Strada C. A. Rosetti 13",
                };

                map.Pins.Add(pin1);
                map.Pins.Add(pin2);
                map.Pins.Add(pin3);
                map.Pins.Add(pin4);
                map.Pins.Add(pin5);
                map.Pins.Add(pin6);

                Content = map;
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 35
0
 private void MoveMapToFrance()
 {
     map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(46.880169, 2.659286), Distance.FromMiles(300)));
 }
Ejemplo n.º 36
0
        public async void getPolyLine1()
        {
            if (!string.IsNullOrEmpty(PickUpLatitude) && !string.IsNullOrEmpty(PickUpLongitude))
            {
                try
                {
                    try
                    {
                        try
                        {
                            RootObjectPolyLine obj = new RootObjectPolyLine();
                            obj = await CommonLib.GetPolyLine(Convert.ToDouble(PickUpLatitude), Convert.ToDouble(PickUpLongitude), Convert.ToDouble(DestinationLatitude), Convert.ToDouble(DestinationLongitude));

                            string points = string.Empty;
                            foreach (var data in obj.routes)
                            {
                                points = data.overview_polyline.points;
                                foreach (var time in data.legs)
                                {
                                    Time         = time.duration.text;
                                    timeTxt.Text = Time;
                                }
                            }

                            poliList = CommonLib.DecodePoly(points);
                        }
                        catch (Exception)
                        {
                        }
                        try
                        {
                            double dic = Calc(Convert.ToDouble(PickUpLatitude), Convert.ToDouble(PickUpLongitude), Convert.ToDouble(DestinationLatitude), Convert.ToDouble(DestinationLongitude));
                            if (poliList != null)
                            {
                                double destination_Latitude  = 0;
                                double destination_Longitude = 0;
                                foreach (var data in poliList)
                                {
                                    customMap.RouteCoordinates.Add(new Position(data.Latitude, data.Longitude));
                                    destination_Latitude  = data.Latitude;
                                    destination_Longitude = data.Longitude;
                                }


                                var start_pin = new CustomPin
                                {
                                    Pin = new Pin
                                    {
                                        Type     = PinType.Place,
                                        Position = new Position(Convert.ToDouble(PickUpLatitude), Convert.ToDouble(PickUpLongitude)),
                                        //  Position = new Position(30.706459, 76.708265),
                                        Label = "Driver",
                                        // Address = storeAddress
                                    },
                                    Id       = "Xamarin",
                                    startPin = true
                                };
                                var destination_pin = new CustomPin
                                {
                                    Pin = new Pin
                                    {
                                        Type     = PinType.Place,
                                        Position = new Position(Convert.ToDouble(DestinationLatitude), Convert.ToDouble(DestinationLongitude)),
                                        // Position = new Position(30.7024, 76.8215),
                                        Label = "Customer",
                                        // Address = customerAddress
                                    },
                                    Id = "1",
                                };

                                //var shop_pin = new CustomPin
                                //{
                                //    Pin = new Pin
                                //    {
                                //        Type = PinType.Place,
                                //        Position = new Position(Convert.ToDouble(ShopLatitude), Convert.ToDouble(ShopLongitude)),
                                //        Label = ShopName,
                                //    },
                                //    Id = "Shop",
                                //};



                                customMap.CustomPins = new List <CustomPin> {
                                    start_pin, destination_pin
                                };
                                if (Device.OS == TargetPlatform.iOS)
                                {
                                    customMap.Pins.Add(start_pin.Pin);
                                    customMap.Pins.Add(destination_pin.Pin);
                                }

                                customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(Convert.ToDouble(PickUpLatitude), Convert.ToDouble(PickUpLongitude)), Xamarin.Forms.Maps.Distance.FromKilometers(dic)));
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    catch (Exception ex)
                    {
                    }

                    //
                }
                catch (Exception)
                {
                }
            }
            else
            {
                var locator  = CrossGeolocator.Current;
                var position = await locator.GetPositionAsync(10000);


                try
                {
                    try
                    {
                        try
                        {
                            RootObjectPolyLine obj = new RootObjectPolyLine();
                            obj = await CommonLib.GetPolyLine(Convert.ToDouble(position.Latitude), Convert.ToDouble(position.Longitude), Convert.ToDouble(ShopLatitude), Convert.ToDouble(ShopLongitude));

                            string points = string.Empty;
                            foreach (var data in obj.routes)
                            {
                                points = data.overview_polyline.points;
                                foreach (var time in data.legs)
                                {
                                    Time         = time.duration.text;
                                    timeTxt.Text = Time;
                                }
                            }

                            poliList = CommonLib.DecodePoly(points);
                        }
                        catch (Exception)
                        {
                        }
                        try
                        {
                            double dic = Calc(Convert.ToDouble(position.Latitude), Convert.ToDouble(position.Longitude), Convert.ToDouble(ShopLatitude), Convert.ToDouble(ShopLongitude));
                            if (poliList != null)
                            {
                                double destination_Latitude  = 0;
                                double destination_Longitude = 0;
                                foreach (var data in poliList)
                                {
                                    customMap.RouteCoordinates.Add(new Position(data.Latitude, data.Longitude));
                                    destination_Latitude  = data.Latitude;
                                    destination_Longitude = data.Longitude;
                                }



                                var destination_pin = new CustomPin
                                {
                                    Pin = new Pin
                                    {
                                        Type     = PinType.Place,
                                        Position = new Position(Convert.ToDouble(position.Latitude), Convert.ToDouble(position.Longitude)),
                                        Label    = "Customer",
                                    },
                                    Id = "1",
                                };

                                var shop_pin = new CustomPin
                                {
                                    Pin = new Pin
                                    {
                                        Type     = PinType.Place,
                                        Position = new Position(Convert.ToDouble(ShopLatitude), Convert.ToDouble(ShopLongitude)),
                                        Label    = ShopName,
                                    },
                                    Id = "Shop",
                                };



                                customMap.CustomPins = new List <CustomPin> {
                                    destination_pin, shop_pin
                                };
                                if (Device.OS == TargetPlatform.iOS)
                                {
                                    customMap.Pins.Add(destination_pin.Pin);
                                    customMap.Pins.Add(shop_pin.Pin);
                                }

                                customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(Convert.ToDouble(position.Latitude), Convert.ToDouble(position.Longitude)), Xamarin.Forms.Maps.Distance.FromKilometers(dic)));
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    catch (Exception ex)
                    {
                    }

                    //
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 37
0
 public CustomMap(MapSpan region) : base(region)
 {
 }
Ejemplo n.º 38
0
 void OnMoveToRegionMessage(Map s, MapSpan a)
 {
     MoveToRegion(a, true);
 }
Ejemplo n.º 39
0
        private static void VisibleRegionChanged(BindableObject bindable, MapSpan oldValue, MapSpan newValue)
        {
            var behavior = bindable as MapBehavior;

            if (behavior == null)
            {
                return;
            }
            behavior.SetVisibleRegion(oldValue, newValue);
        }
Ejemplo n.º 40
0
 public CustomMap(MapSpan mapSpan)
     : base(mapSpan)
 {
 }
Ejemplo n.º 41
0
		void OnMoveToRegionMessage (Map s, MapSpan a)
		{
			MoveToRegion (a, true);
		}
        private void MoveToRegion(MapSpan span, bool animate)
        {
            if (this.NativeMap == null)
            {
                return;
            }
            //			span = span.ClampLatitude (85.0, -85.0);

            LatLng northeast = new LatLng (span.Center.Latitude + span.LatitudeDegrees / 2.0, span.Center.Longitude + span.LongitudeDegrees / 2.0);
            CameraUpdate update = CameraUpdateFactory.NewLatLngBounds (new LatLngBounds (new LatLng (span.Center.Latitude - span.LatitudeDegrees / 2.0, span.Center.Longitude - span.LongitudeDegrees / 2.0), northeast), 0);
            try
            {
                this.NativeMap.MoveCamera (update);
            } catch (IllegalStateException ex)
            {
            }
        }
Ejemplo n.º 43
0
 public CustomMap(MapSpan map)
 {
     visibleRegion = map;
 }
 public MoveToRegionMessage(MapSpan mapSpan, bool animate = true)
 {
     this.Span = mapSpan;
     this.Animate = animate;
 }
Ejemplo n.º 45
0
 public MyMap(MapSpan region)
     : base(region)
 {
 }
Ejemplo n.º 46
0
 /// <summary>
 /// Overload Contructor MapExtend
 /// </summary>
 /// <param name="mapSpan"></param>
 public MapExtend(MapSpan mapSpan)
     : base(mapSpan)
 {
     polilenes = new ObservableRangeCollection<Position>();
     EPins = new ObservableRangeCollection<PinExtend>();
 }
Ejemplo n.º 47
0
		public void RangeClamping ()
		{
			var span = new MapSpan (new Position (0, 0), -1, -2);
			Assert.IsTrue (span.LatitudeDegrees > 0);
			Assert.IsTrue (span.LongitudeDegrees > 0);
		}
Ejemplo n.º 48
0
 ///<inheritdoc/>
 void IRouteFunctions.SetBounds(MapSpan bounds)
 {
     this.Bounds = bounds;
 }
Ejemplo n.º 49
0
        public GetGeoCS()
        {
            map = new Map(
                MapSpan.FromCenterAndRadius(
                    centerPosition,               // 初期位置
                    Distance.FromKilometers(4d))) // 4km 圏内(?)
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HasZoomEnabled    = true,
                IsShowingUser     = true,
            };

            LatLabel = new Label
            {
                Text = "Lat:",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
            };
            LonLabel = new Label
            {
                Text = "Lon:",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
            };
            AddrLabel = new Label
            {
                Text     = "Address:",
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
            };
            var getGeoButton = new Button
            {
                Text = "Get Location",
            };

            getGeoButton.Clicked += async(sender, e) =>
            {
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;

                var location = await locator.GetPositionAsync(10000);

                LatLabel.Text = "Lat: " + location.Latitude.ToString("N6");
                LonLabel.Text = "Lon: " + location.Longitude.ToString("N6");

                var addr = await getAddress.GetJsonAsync(location.Latitude, location.Longitude) ?? "取得できませんでした";

                AddrLabel.Text = "Address: " + addr;

                // Map を移動させてピン打ち
                map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(location.Latitude, location.Longitude), Distance.FromKilometers(4d)));
                if (map.Pins.Count() > 0)
                {
                    map.Pins.Clear();
                }
                pin = new Pin
                {
                    Position = new Position(location.Latitude, location.Longitude),
                    Label    = addr,
                };
                map.Pins.Add(pin);
            };

            Title   = "XF_GpsSample";
            Content = new StackLayout
            {
                Padding         = new Thickness(8),
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children        =
                {
                    getGeoButton,
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            LatLabel,
                            LonLabel,
                        }
                    },
                    AddrLabel,
                    map
                }
            };
        }
Ejemplo n.º 50
0
        private void UpdatePosition(CameraPosition pos)
        {
            // if any marker is shown, don't invoke camera change
            var northWest = NativeMap.Projection.FromScreenLocation(new Android.Graphics.Point(0, 0)).ToPosition();
            var center = pos.Target.ToPosition();
            var distanceInDegrees = northWest.DistanceFrom(center);

            var bound = new MapSpan(new Position(center.Latitude, center.Longitude),
                            distanceInDegrees.Latitude * 2, distanceInDegrees.Longitude * 2);
            OnCameraChange(bound, pos);

            MessagingCenter.Send<IMapRenderer, MapMessage>(this, MapMessage.RendererMessage, new ViewChangeMessage(MapEx) { Span = bound, ZoomLevel = pos.Zoom });
        }
Ejemplo n.º 51
0
		void MoveToRegion(MapSpan mapSpan, bool animated = true)
		{
			Position center = mapSpan.Center;
			var mapRegion = new MKCoordinateRegion(new CLLocationCoordinate2D(center.Latitude, center.Longitude), new MKCoordinateSpan(mapSpan.LatitudeDegrees, mapSpan.LongitudeDegrees));
			((MKMapView)Control).SetRegion(mapRegion, animated);
		}
Ejemplo n.º 52
0
        async void Handle_Clicked(object sender, System.EventArgs e)
        {
            //var response = await CrossPermissions.Current.RequestPermissionsAsync(Permission.LocationWhenInUse);
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

            if (status != Plugin.Permissions.Abstractions.PermissionStatus.Granted)
            {
                if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.LocationWhenInUse))
                {
                    //await DisplayAlert("Need location", "Gunna need that location", "OK");
                }

                var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.LocationWhenInUse);

                //Best practice to always check that the key exists
                if (results.ContainsKey(Permission.LocationWhenInUse))
                {
                    status = results[Permission.LocationWhenInUse];
                }
            }

            if (status == Plugin.Permissions.Abstractions.PermissionStatus.Granted)
            {
                map.MapType = MapType.Satellite;
                var location = await Geolocation.GetLocationAsync();

                //var location = await Geolocation.GetLastKnownLocationAsync();

                if (location != null)
                {
                    Pin currentPin = new Pin()
                    {
                        Type     = PinType.Generic,
                        Label    = "Current",
                        Address  = "Current Location",
                        Position = new Position(location.Latitude, location.Longitude),
                        //Rotation = 33.3f,
                        Tag = "id_tokyo"
                    };

                    map.Pins.Add(currentPin);
                    // Add Circles
                    var circle1 = new Circle();
                    circle1.StrokeWidth = 2f;
                    circle1.StrokeColor = Color.Red;
                    circle1.FillColor   = Color.Transparent;
                    circle1.Center      = new Position(location.Latitude, location.Longitude);
                    circle1.Radius      = Distance.FromMeters(50);
                    map.Circles.Add(circle1);
                    //map.Circles.Add(CreateShiftedCircle(circle1, 0d, 0.05d, Color.Yellow));
                    //map.Circles.Add(CreateShiftedCircle(circle1, 0d, 0.10d, Color.Green));
                    map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                         new Position(location.Latitude, location.Longitude), Distance.FromMiles(0.3)));

                    Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
                }
            }
            else if (status != Plugin.Permissions.Abstractions.PermissionStatus.Unknown)
            {
            }


            try
            {
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                // Handle not supported on device exception
            }
            catch (FeatureNotEnabledException fneEx)
            {
                // Handle not enabled on device exception
            }
            catch (PermissionException pEx)
            {
                // Handle permission exception
            }
            catch (Exception ex)
            {
                // Unable to get location
            }
        }
Ejemplo n.º 53
0
 protected virtual void OnCameraChange(MapSpan span, CameraPosition pos)
 {
 }
Ejemplo n.º 54
0
 private void MoveToLocation(double Latitude, double Longitude, int fromMiles)
 {
     ConvenientCareMap.MoveToRegion(
         MapSpan.FromCenterAndRadius(
             new Position(Latitude, Longitude), Distance.FromMiles(fromMiles)));
 }
Ejemplo n.º 55
0
		private void HandleCenterLocation()
		{
			if (App.GPS.LastKnownPosition != null)
			{
				visibleRegion = MapSpan.FromCenterAndRadius(new Position(App.GPS.LastKnownPosition.Latitude, App.GPS.LastKnownPosition.Longitude), Distance.FromMeters(1000));
			}
			else
			{
				visibleRegion = MapSpan.FromCenterAndRadius(new Position(0, 0), Distance.FromMeters(1000));
			}

			map.MoveToRegion(visibleRegion);
		}
Ejemplo n.º 56
0
        void initMap()
        {
            if (_selectable)
            {
                PlacesAutocomplete.IsVisible            = true;
                PlacesAutocomplete.PlaceSelectedCommand = PlaceSelectedCommand;
                Map.Margin = new Thickness(0, 60, 0, 0);

                Observable.FromAsync(() => GetCurrentLocation())
                .ObserveOn(RxApp.MainThreadScheduler)
                .Where((Position) => Position != null)
                .Subscribe((Position) =>
                {
                    var MapRegion = MapSpan.FromCenterAndRadius(
                        new Xamarin.Forms.Maps.Position(Position.Latitude, Position.Longitude),
                        Distance.FromKilometers(2));

                    Map.MoveToRegion(MapRegion);

                    PlacesAutocomplete.Bounds = MapRegion;
                });

                initTapHandler();

                if (_school != null)
                {
                    Title.Text = !string.IsNullOrWhiteSpace(_school.Name) ?
                                 String.Format(AppResources.EditSon_School_Map_Select, _school.Name) :
                                 AppResources.EditSon_School_Map_Select2;
                }
                else
                {
                    Title.Text = AppResources.EditSon_School_Map_Select2;
                }
            }
            else
            {
                PlacesAutocomplete.IsVisible = false;

                if (_school != null)
                {
                    var MapRegion = MapSpan.FromCenterAndRadius(
                        new Xamarin.Forms.Maps.Position(_school.Latitude, _school.Longitude),
                        Distance.FromKilometers(2));

                    Map.MoveToRegion(MapRegion);

                    Title.Text = !string.IsNullOrWhiteSpace(_school.Name) ?
                                 String.Format(AppResources.EditSon_School_Map_Visualize, _school.Name) :
                                 AppResources.EditSon_School_Map_Visualize2;

                    Map.Pins.Add(new Pin
                    {
                        Type     = PinType.Place,
                        Position = new Xamarin.Forms.Maps.Position(_school.Latitude, _school.Longitude),
                        Label    = _school.Name
                    });
                }
                else
                {
                    Title.Text = AppResources.EditSon_School_Map_Visualize2;
                }
            }
        }
Ejemplo n.º 57
0
		private void HandleCenterBoth()
		{
			WF.Player.Core.CoordBounds bounds = new WF.Player.Core.CoordBounds();

			if (App.Game != null)
			{
				// Map is viewed inside the game
				bounds = App.Game.Bounds;

				if (bounds == null)
				{
					return;
				}
			}
			else
			{
				// Map is viewed outside the game, so show StartingLocation
				bounds = new WF.Player.Core.CoordBounds(StartingLocation.Longitude, StartingLocation.Latitude, StartingLocation.Longitude, StartingLocation.Latitude);
			}

			if (App.GPS.LastKnownPosition != null)
			{
				bounds.Inflate(new WF.Player.Core.ZonePoint(App.GPS.LastKnownPosition.Latitude, App.GPS.LastKnownPosition.Longitude, 0));
			}

			visibleRegion = new MapSpan(new Xamarin.Forms.Maps.Position(bounds.Center.Latitude, bounds.Center.Longitude), Math.Abs(bounds.Top - bounds.Bottom) * 1.1, Math.Abs(bounds.Right - bounds.Left) * 1.1);

			map.MoveToRegion(visibleRegion);
		}
Ejemplo n.º 58
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TreeWatch.FieldMap"/> class.
 /// </summary>
 public FieldMap()
     : this(MapSpan.FromCenterAndRadius(new Position(), Distance.FromKilometers(1)))
 {
 }
Ejemplo n.º 59
0
		/// <summary>
		/// Constructor that takes a region
		/// </summary>
		/// <param name="region"></param>
		public ExtMap(MapSpan region)
			: base(region)
		{

		}
Ejemplo n.º 60
0
 private void MoveMap(Position position)
 {
     MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(
                            position,
                            Distance.FromKilometers(.2)));
 }