Exemplo n.º 1
0
        /*
         * async void getPinData()
         * {
         *      using (var client = new HttpClient())
         *      {
         *
         * client.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0");
         *  requests = new List<Models.ActiveRequest>();
         *  riders = new List<Models.Rider>();
         *
         *  var reqResponse = await client.GetAsync("http://thehopper.azurewebsites.net/api/ActiveRequests/");
         *  //This will be an IQueryable object
         *  var reqResponseStr = await reqResponse.Content.ReadAsStringAsync();
         *  //The following will convert the json to an actual rider object
         *  requests = JsonConvert.DeserializeObject<List<Models.ActiveRequest>>(reqResponseStr);
         *  updateRequests(requests);
         *
         *  //Same process here
         *  var riderResponse = await client.GetAsync("http://thehopper.azurewebsites.net/api/riders/");
         *  var riderResponseStr = await riderResponse.Content.ReadAsStringAsync();
         *  riders = JsonConvert.DeserializeObject<List<Models.Rider>>(riderResponseStr);
         *  updateRiders(riders);
         * } catch(ArgumentNullException e)
         * {
         *  await DisplayAlert("GET Request Failed" , "Could not get requests (NullArg)", "OK");
         * }
         * //DEBUG Stuff
         * for(int i = 0; i < requests.Count; i++)
         * {
         *  Debug.WriteLine("Request " + i + ": " + requests.ElementAt(i).ID);
         * }
         * for (int i = 0; i < riders.Count; i++)
         * {
         *  Debug.WriteLine("Rider " + i + ": " + riders.ElementAt(i).ID);
         * }
         * //end
         * }
         * }*/
        void recenterMap()
        {
            //No guarantee to have all pins on the map.  Just recenters the map around the average lat and long of all pins - 1.5 mile radius
            var pos = new Xamarin.Forms.GoogleMaps.Position(avgLat, avgLong);

            map.MoveToRegion(MapSpan.FromCenterAndRadius(pos, Distance.FromMiles(1.5)));
        }
        async void Update(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (map.Pins.Count == 1)
            {
                return;
            }

            var cPin = map.Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                });

                await map.MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));

                var previousPosition = map.Polylines.FirstOrDefault().Positions.FirstOrDefault();
                map.Polylines?.FirstOrDefault()?.Positions?.Remove(previousPosition);
            }
            else
            {
                //END TRIP
                map.Polylines?.FirstOrDefault()?.Positions?.Clear();
            }
        }
        async void UpdateRoute(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (map.Pins.Count == 1 && map.Polylines != null && map.Polylines?.Count > 1)
            {
                return;
            }

            var cPin = map.Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = (Device.RuntimePlatform == Device.iOS) ? BitmapDescriptorFactory.FromView(new Image()
                {
                    Source        = "car.png",
                    WidthRequest  = 25,
                    HeightRequest = 25
                }) : BitmapDescriptorFactory.DefaultMarker(Color.Purple);

                await map.MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));

                var previousPosition = map?.Polylines?.FirstOrDefault()?.Positions?.FirstOrDefault();
                map.Polylines?.FirstOrDefault()?.Positions?.Remove(previousPosition.Value);
            }
            else
            {
                //END TRIP
                map.Polylines?.FirstOrDefault()?.Positions?.Clear();
            }
        }
Exemplo n.º 4
0
        async void Update(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (Pins.Count == 1 && Polylines != null && Polylines?.Count > 1)
            {
                return;
            }

            var cPin = Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = (Device.RuntimePlatform == Device.Android) ? BitmapDescriptorFactory.FromBundle("ic_taxi.png") : BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                });

                await MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));

                var previousPosition = Polylines?.FirstOrDefault()?.Positions?.FirstOrDefault();
                Polylines?.FirstOrDefault()?.Positions?.Remove(previousPosition.Value);
            }
            else
            {
                //END TRIP
                Polylines?.FirstOrDefault()?.Positions?.Clear();
            }
        }
Exemplo n.º 5
0
        public MapPage()
        {
            InitializeComponent();
            if (Connectivity.NetworkAccess != NetworkAccess.Internet)
            {
                DisplayAlert("Отсутствует подключение к сети", null, null, "OK");
                return;
            }
            for (int i = 0; i < MyListPage.events.Count; i++)
            {
                if (ContentManager.ActualEvents[i].HasCoords)
                {
                    Xamarin.Forms.Maps.Pin mapPin = new Xamarin.Forms.Maps.Pin
                    {
                        Type     = Xamarin.Forms.Maps.PinType.Place,
                        Position = new Xamarin.Forms.Maps.Position(ContentManager.ActualEvents[i].Lat, ContentManager.ActualEvents[i].Lon),
                        Label    = ContentManager.ActualEvents[i].Title,
                        Address  = ContentManager.ActualEvents[i].Address
                    };
                    MyMap.Pins.Add(mapPin);
                    positions.Add(ContentManager.ActualEvents[i]);
                    mapPin.InfoWindowClicked += async(s, args) =>
                    {
                        foreach (var item in ContentManager.ActualEvents)
                        {
                            if (item.Title.Equals(((Xamarin.Forms.Maps.Pin)s).Label))
                            {
                                try
                                {
                                    await Navigation.PushModalAsync(new Detail(item));
                                }
                                catch (Java.Lang.RuntimeException)
                                {
                                    await DisplayAlert("Ошибка выгрузки события", null, null, "OK");

                                    ContentManager.ActualEvents.Remove(item);
                                }
                            }
                        }
                    };
                }
            }
            var myPos = new Xamarin.Forms.Maps.Pin
            {
                Type     = Xamarin.Forms.Maps.PinType.SearchResult,
                Position = new Xamarin.Forms.Maps.Position(MyLat, MyLon),
                Label    = "Me",
                Address  = ""
            };

            MyMap.Pins.Add(myPos);
            Xamarin.Forms.GoogleMaps.Position posit = new Xamarin.Forms.GoogleMaps.Position(MyLat, MyLon);
            CameraPosition cameraPosition           = new CameraPosition(posit, 18, 155, 65);
            CameraUpdate   cameraUpdate             = CameraUpdateFactory.NewCameraPosition(cameraPosition);

            Xamarin.Forms.Maps.Position post = new Xamarin.Forms.Maps.Position(MyLat + 1, MyLon + 1);
            Xamarin.Forms.Maps.MapSpan  sp   = new Xamarin.Forms.Maps.MapSpan(post, MyLat, MyLon);
            MyMap.MoveToRegion(sp);
        }
Exemplo n.º 6
0
        private void CenterMapOnEurope()
        {
            var mapPosition = new Position(50.2649, 28.6767);

            Map.MoveToRegion(MapSpan.FromCenterAndRadius(
                                 new Position(mapPosition.Latitude, mapPosition.Longitude),
                                 Distance.FromMiles(2000)));
        }
Exemplo n.º 7
0
 //Crea registro
 public DireccionModificar(Xamarin.Forms.GoogleMaps.Position MyPosicion, ListView LvDireccion)
 {
     InitializeComponent();
     this.MyPosicion = MyPosicion;
     MIDireccion();
     Latitud       = MyPosicion.Latitude.ToString();
     Longitud      = MyPosicion.Longitude.ToString();
     LVDirecciones = LvDireccion;
 }
Exemplo n.º 8
0
        public async void display(double a, double b)
        {
            var position          = new Xamarin.Forms.GoogleMaps.Position(a, b);
            var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);

            foreach (var address in possibleAddresses)
            {
                lblAddress.Text += address + "\n";
            }
        }
Exemplo n.º 9
0
 //actualiza registro
 public DireccionModificar(Xamarin.Forms.GoogleMaps.Position MyPosicion, VMDireccion objDireccion, ListView ListDirecciones)
 {
     InitializeComponent();
     this.MyPosicion = MyPosicion;
     MIDireccion();
     txtID.Text    = objDireccion.ID.ToString();
     Latitud       = MyPosicion.Latitude.ToString();
     Longitud      = MyPosicion.Longitude.ToString();
     LVDirecciones = ListDirecciones;
 }
Exemplo n.º 10
0
        async void Update(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (mapn.Pins.Count == 1 && mapn.Polylines != null && mapn.Polylines?.Count > 1)
            {
                return;
            }
            var cPin = mapn.Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                });

                await mapn.MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));
            }
        }
Exemplo n.º 11
0
        private async void GetCountryFromTap(Position clickPosition)
        {
            var lat = clickPosition.Latitude;
            var lon = clickPosition.Longitude;

            var placemarks = await Geocoding.GetPlacemarksAsync(lat, lon);

            var placemark = placemarks?.FirstOrDefault();

            var countryName = placemark.CountryCode;

            var country = AvailableCountries.FirstOrDefault(x => x.CountryId == countryName);

            if (country != null)
            {
                _countryPopUp = new CountryPopUpPage(country.Id, country.Name);
                await PopupNavigation.Instance.PushAsync(_countryPopUp);
            }
        }
Exemplo n.º 12
0
 private async void GpsTrecking(object sender, PositionEventArgs e)
 {
     await Task.Run(() =>
     {
         Position position = map.Polylines[0].Positions[0];
         if ((position.Latitude < e.Position.Latitude + 0.000020 && position.Latitude > e.Position.Latitude - 0.000020) && (position.Longitude < e.Position.Longitude + 0.000020 && position.Longitude > e.Position.Longitude - 0.000020))
         {
             map.Polylines[0].Positions.Remove(position);
             return;
         }
         if ((e.Position.Latitude - position.Latitude > 0.000040 || e.Position.Latitude - position.Latitude < -0.000040 || position.Longitude - e.Position.Longitude > 0.000040 || position.Longitude - e.Position.Longitude < -0.000040))
         {
             if (isRefreshPolylines)
             {
                 isRefreshPolylines = false;
                 RefreshPoly();
             }
         }
     });
 }
        private void UpdateMap(Plugin.Geolocator.Abstractions.Position position)
        {
            try
            {
                var gFormsPos = new Xamarin.Forms.GoogleMaps.Position(position.Latitude, position.Longitude);
                MyLocation.Clear();
                MyLocation.Add(new Pin()
                {
                    Position = gFormsPos,
                    Label    = "My Position"
                });


                MoveToRegionRequest.MoveToRegion(MapSpan.FromCenterAndRadius(gFormsPos,
                                                                             Distance.FromKilometers(1)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 14
0
        public SuddnMap()
        {//tae
            InitializeComponent();
            // Xamarin.FormsGoogleMaps.Init("AIzaSyC-vMol82Gj9OVkewE09ADdKMhduW77qgo"); //initialize the map -ios.


            //var map = new Map(
            //MapSpan.FromCenterAndRadius(
            ////new Position(14.55, 121.0244), Distance.FromMiles(0.3)))
            var position = new Xamarin.Forms.GoogleMaps.Position(14.5599303, 121.0135896);

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

            var pin = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type = Xamarin.Forms.GoogleMaps.PinType.Place,

                Position = position,
                Label    = "my position"
            };
            //gMap.MapType = Xamarin.Forms.GoogleMaps.MapType.Street;
            //gMap.Pins.Add(pin);
            //gMap.MoveToRegion(Xamarin.Forms.GoogleMaps.MapSpan.FromCenterAndRadius(position, Xamarin.Forms.GoogleMaps.Distance.FromMiles(1)));


            //var stack = new StackLayout { Spacing = 0 };
            //stack.Children.Add(gMap);
            //Content = stack;


            //map.MapType == MapType.Street;
        }
Exemplo n.º 15
0
        public async Task <string> getAddressForPosition(Xamarin.Forms.GoogleMaps.Position position)
        {
            var address = await geoCoder.GetAddressesForPositionAsync(position).ConfigureAwait(false);

            return(address.First().Split('\n')[0]);
        }
Exemplo n.º 16
0
        async void Calculate(List <Xamarin.Forms.GoogleMaps.Position> list)
        {
            searchLayout.IsVisible    = true;
            stopRouteButton.IsVisible = false;
            Chamada.IsVisible         = true;

            map.Polylines.Clear();
            var polyline = new Xamarin.Forms.GoogleMaps.Polyline();


            polyline.StrokeColor = Color.Green;

            polyline.StrokeWidth = (float)5;



            foreach (var p in list)
            {
                polyline.Positions.Add(p);
            }
            map.Polylines.Add(polyline);


            var pin = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Xamarin.Forms.GoogleMaps.Position(polyline.Positions.First().Latitude, polyline.Positions.First().Longitude),
                Label    = "First",
                Address  = "First",
                Tag      = string.Empty,
                Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                })
            };

            map.Pins.Add(pin);

            var pin1 = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Xamarin.Forms.GoogleMaps.Position(polyline.Positions.Last().Latitude, polyline.Positions.Last().Longitude),
                Label    = "Last",
                Address  = "Last",
                Tag      = string.Empty
            };

            map.Pins.Add(pin1);



            //var medio = polyline.Positions.Count/ 2;


            //var pinmedio = new Xamarin.Forms.GoogleMaps.Pin
            //{
            //Type = PinType.Place,

            //Position = new Position(polyline.Positions[medio].Latitude, polyline.Positions[medio].Longitude),

            //Label = "Medio",
            //Address = "Medio",
            //Tag = string.Empty,

            //};

            //map.Pins.Add(pinmedio);



            inicio = pin.Position;

            fim = pin1.Position;

            map.MoveToRegion(MapSpan.FromPositions(list).WithZoom(0.85));

            await StartListening();
        }
Exemplo n.º 17
0
 void MoveMap()
 {
     Xamarin.Forms.GoogleMaps.Position xamPos = new Xamarin.Forms.GoogleMaps.Position(42.003724, 21.435270);
     googleMap.MoveToRegion(MapSpan.FromCenterAndRadius(xamPos, Distance.FromMiles(0.6)));
 }
Exemplo n.º 18
0
 public static MapSpan FromCenterAndRadius(Position center, Distance radius)
 {
     return new MapSpan(center, 2 * DistanceToLatitudeDegrees(radius), 2 * DistanceToLongitudeDegrees(center, radius));
 }
Exemplo n.º 19
0
        private void Map_OnMapClicked(object sender, MapClickedEventArgs e)
        {
            var position = new Position(e.Point.Latitude, e.Point.Longitude);

            GetCountryFromTap(position);
        }
Exemplo n.º 20
0
 static double LongitudeDegreesToKm(Position position, double longitudeDegrees)
 {
     double latCircumference = LatitudeCircumferenceKm(position);
     return latCircumference * longitudeDegrees / 360;
 }
Exemplo n.º 21
0
 static double LatitudeCircumferenceKm(Position position)
 {
     return EarthCircumferenceKm * Math.Cos(position.Latitude * Math.PI / 180.0);
 }
Exemplo n.º 22
0
        const double MinimumRangeDegrees = 0.001 / EarthCircumferenceKm * 360; // 1 meter

        public MapSpan(Position center, double latitudeDegrees, double longitudeDegrees)
        {
            Center = center;
            LatitudeDegrees = Math.Min(Math.Max(latitudeDegrees, MinimumRangeDegrees), 90.0);
            LongitudeDegrees = Math.Min(Math.Max(longitudeDegrees, MinimumRangeDegrees), 180.0);
        }
Exemplo n.º 23
0
 static double DistanceToLongitudeDegrees(Position position, Distance distance)
 {
     double latCircumference = LatitudeCircumferenceKm(position);
     return distance.Kilometers / latCircumference * 360;
 }
Exemplo n.º 24
0
 public static Geo.Position GoogleMapsToGeolocator(this GMaps.Position position)
 {
     return(new Geo.Position(position.Latitude, position.Longitude));
 }
Exemplo n.º 25
0
 public Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position)
 {
     if (GetAddressesForPositionFuncAsync == null)
         throw new InvalidOperationException("You MUST call Xamarin.FormsMaps.Init (); prior to using it.");
     return GetAddressesForPositionFuncAsync(position);
 }
Exemplo n.º 26
0
 private Pin GetCustomPin(Xamarin.Forms.GoogleMaps.Position marker)
 {
     return(pins.FirstOrDefault(x => x.Position.Latitude == marker.Latitude && x.Position.Longitude == marker.Longitude));
 }