Polygon Getpolygondata() { var polygon = new Xamarin.Forms.GoogleMaps.Polygon(); polygon.Positions.Add(new Position(41.1389019841448d, -8.61560349288011d)); polygon.Positions.Add(new Position(41.1434744495776d, -8.67074812896517d)); polygon.Positions.Add(new Position(41.1449838609599d, -8.67905202242122d)); polygon.Positions.Add(new Position(41.1451299199957d, -8.67927438576518d)); polygon.Positions.Add(new Position(41.1667491884192d, -8.69051961393614d)); polygon.Positions.Add(new Position(41.1687515832633d, -8.69128901091482d)); polygon.Positions.Add(new Position(41.1687718202548d, -8.69129406942044d)); polygon.Positions.Add(new Position(41.1733985483824d, -8.6901233398917d)); polygon.Positions.Add(new Position(41.1791950462077d, -8.66638025932549d)); polygon.Positions.Add(new Position(41.1843186499419d, -8.64263275539779d)); polygon.Positions.Add(new Position(41.1859199810206d, -8.60475022412726d)); polygon.Positions.Add(new Position(41.1859353051989d, -8.60415557268555d)); polygon.Positions.Add(new Position(41.1858564905415d, -8.60352615847566d)); polygon.Positions.Add(new Position(41.1809534888858d, -8.57618203495341d)); polygon.Positions.Add(new Position(41.1808879776888d, -8.57596086663742d)); polygon.Positions.Add(new Position(41.1782338392238d, -8.56918812805673d)); polygon.Positions.Add(new Position(41.1781107344154d, -8.5690029395442d)); polygon.Positions.Add(new Position(41.1778608190979d, -8.56863743584061d)); polygon.Positions.Add(new Position(41.1776820677363d, -8.56838121049044d)); polygon.Positions.Add(new Position(41.1772845426276d, -8.56783274898752d)); polygon.Positions.Add(new Position(41.1761404097255d, -8.56630188826643d)); polygon.Positions.Add(new Position(41.1760550093552d, -8.56619263815834d)); polygon.Positions.Add(new Position(41.1759695143603d, -8.56610877045314d)); polygon.Positions.Add(new Position(41.1600578943756d, -8.55337925107515d)); polygon.Positions.Add(new Position(41.158207085713d, -8.55261345505833d)); polygon.Positions.Add(new Position(41.1532077014578d, -8.55473745611279d)); polygon.Positions.Add(new Position(41.1529458174769d, -8.55494508426352d)); polygon.Positions.Add(new Position(41.1463677636723d, -8.56368877972558d)); polygon.Positions.Add(new Position(41.1399578511665d, -8.57576315330342d)); polygon.Positions.Add(new Position(41.1383506797128d, -8.59418349674972d)); polygon.IsClickable = true; polygon.StrokeColor = Color.Black; polygon.StrokeWidth = 3f; polygon.FillColor = Color.FromRgba(255, 0, 0, 64); polygon.Tag = "POLYGON"; return(polygon); }
async Task <bool> GetHeatMap(Bounds bounds) { // set the size of the pixel in degrees lat / lon map.Polygons.Clear(); map.Polylines.Clear(); // build the request for polution info var request = new PollutionRequest(); request.RAD = 100; request.PAIRS = new List <List <string> >(); var radius = Math.Max(bounds.HeightDegrees / 2, bounds.WidthDegrees / 2); var unit = Math.Max(.0015, radius / 100); var halfU = unit / 2; var left = Convert.ToDouble((bounds.Center.Longitude + radius * 2).ToString("F6")); var right = Convert.ToDouble((bounds.Center.Longitude - radius * 2).ToString("F6")); var top = Convert.ToDouble((bounds.Center.Latitude + radius).ToString("F6")); var bottom = Convert.ToDouble((bounds.Center.Latitude - radius).ToString("F6")); for (var Y = bottom; Y <= top; Y += unit) { for (var X = left; X >= right; X -= unit) { List <string> point = new List <string>(); point.Add(Y.ToString()); point.Add(X.ToString()); (request.PAIRS).Add(point); if (request.PAIRS.Count >= 400 || (Y + unit > top && X - unit < right)) { var result = await rest.GetPollution(JsonConvert.SerializeObject(request)); if (result != null) { // get the results var x = 0; double lvl = 0; // loop through the results for (x = 0; x < result.lon.Count; x++) { string level = (result.val)[x]; lvl = Convert.ToDouble(level) * 1; Color fc = Color.Black; if (lvl <= 50) { fc = Color.Green; } else { if (lvl <= 100) { fc = Color.Yellow; } else { fc = Color.Red; } } var north = Convert.ToDouble(result.lat[x]) * 1 + halfU * 1; var south = Convert.ToDouble(result.lat[x]) * 1 - halfU * 1; var east = Convert.ToDouble(result.lon[x]) * 1 + halfU * 1; var west = Convert.ToDouble(result.lon[x]) * 1 - halfU * 1; var tileBounds = new Bounds(new Position(south, west), new Position(north, east)); var rectangle = new Xamarin.Forms.GoogleMaps.Polygon(); rectangle.StrokeWidth = 0; rectangle.FillColor = Color.FromRgba(255, 0, 0, (lvl / 30.0) - 0.25); rectangle.Positions.Add(tileBounds.NorthEast); rectangle.Positions.Add(tileBounds.NorthWest); rectangle.Positions.Add(tileBounds.SouthWest); rectangle.Positions.Add(tileBounds.SouthEast); map.Polygons.Add(rectangle); } } request.PAIRS.Clear(); } } } return(true); }
void Calculate(List <Xamarin.Forms.GoogleMaps.Position> list) { mapn.Polylines.Clear(); var polygon = new Xamarin.Forms.GoogleMaps.Polygon(); polygon.Positions.Add(new Position(41.1389019841448d, -8.61560349288011d)); polygon.Positions.Add(new Position(41.1434744495776d, -8.67074812896517d)); polygon.Positions.Add(new Position(41.1449838609599d, -8.67905202242122d)); polygon.Positions.Add(new Position(41.1451299199957d, -8.67927438576518d)); polygon.Positions.Add(new Position(41.1667491884192d, -8.69051961393614d)); polygon.Positions.Add(new Position(41.1687515832633d, -8.69128901091482d)); polygon.Positions.Add(new Position(41.1687718202548d, -8.69129406942044d)); polygon.Positions.Add(new Position(41.1733985483824d, -8.6901233398917d)); polygon.Positions.Add(new Position(41.1791950462077d, -8.66638025932549d)); polygon.Positions.Add(new Position(41.1843186499419d, -8.64263275539779d)); polygon.Positions.Add(new Position(41.1859199810206d, -8.60475022412726d)); polygon.Positions.Add(new Position(41.1859353051989d, -8.60415557268555d)); polygon.Positions.Add(new Position(41.1858564905415d, -8.60352615847566d)); polygon.Positions.Add(new Position(41.1809534888858d, -8.57618203495341d)); polygon.Positions.Add(new Position(41.1808879776888d, -8.57596086663742d)); polygon.Positions.Add(new Position(41.1782338392238d, -8.56918812805673d)); polygon.Positions.Add(new Position(41.1781107344154d, -8.5690029395442d)); polygon.Positions.Add(new Position(41.1778608190979d, -8.56863743584061d)); polygon.Positions.Add(new Position(41.1776820677363d, -8.56838121049044d)); polygon.Positions.Add(new Position(41.1772845426276d, -8.56783274898752d)); polygon.Positions.Add(new Position(41.1761404097255d, -8.56630188826643d)); polygon.Positions.Add(new Position(41.1760550093552d, -8.56619263815834d)); polygon.Positions.Add(new Position(41.1759695143603d, -8.56610877045314d)); polygon.Positions.Add(new Position(41.1600578943756d, -8.55337925107515d)); polygon.Positions.Add(new Position(41.158207085713d, -8.55261345505833d)); polygon.Positions.Add(new Position(41.1532077014578d, -8.55473745611279d)); polygon.Positions.Add(new Position(41.1529458174769d, -8.55494508426352d)); polygon.Positions.Add(new Position(41.1463677636723d, -8.56368877972558d)); polygon.Positions.Add(new Position(41.1399578511665d, -8.57576315330342d)); polygon.Positions.Add(new Position(41.1383506797128d, -8.59418349674972d)); polygon.IsClickable = true; polygon.StrokeColor = Color.Black; polygon.StrokeWidth = 3f; polygon.FillColor = Color.FromRgba(255, 0, 0, 64); polygon.Tag = "POLYGON"; mapn.Polygons.Add(polygon); var polyline = new Xamarin.Forms.GoogleMaps.Polyline(); polyline.StrokeColor = Color.Blue; polyline.StrokeWidth = polyline.StrokeWidth * 4; var polylineinside = new Xamarin.Forms.GoogleMaps.Polyline(); polylineinside.StrokeColor = Color.Red; polylineinside.StrokeWidth = polyline.StrokeWidth * 2; foreach (var p in list) { polyline.Positions.Add(p); if (Contains(p, polygon)) { // point is inside polygon polylineinside.Positions.Add(p); } } mapn.Polylines.Add(polyline); if (polylineinside.Positions.Count > 2) { mapn.Polylines.Add(polylineinside); } var pin = new Xamarin.Forms.GoogleMaps.Pin { Type = PinType.Place, Position = new Position(polyline.Positions.First().Latitude, polyline.Positions.First().Longitude), Label = vm.startLabel, Address = vm.startAdd, Tag = "First Point", Icon = BitmapDescriptorFactory.FromView(new Image() { Source = "ic_location.png", WidthRequest = 25, HeightRequest = 25 }) }; mapn.Pins.Add(pin); var pin1 = new Xamarin.Forms.GoogleMaps.Pin { Type = PinType.Place, Position = new Position(polyline.Positions.Last().Latitude, polyline.Positions.Last().Longitude), Label = vm.endLabel, Address = vm.endAdd, Tag = "Last Point", Icon = BitmapDescriptorFactory.FromView(new Image() { Source = "ic_location_red.png", WidthRequest = 25, HeightRequest = 25 }) }; mapn.Pins.Add(pin1); int innerDist = 0; if (polylineinside.Positions.Count > 2) { var googleDirection = (vm.GetDistance(polylineinside.Positions.First(), polylineinside.Positions.Last()).Result); if (googleDirection.Routes != null && googleDirection.Routes.Count > 0) { innerDist = googleDirection.Routes.FirstOrDefault().Legs.FirstOrDefault().Distance.Value; } } int totalDist = vm.CurrentGoogleDirection.Routes.FirstOrDefault().Legs.FirstOrDefault().Distance.Value; decimal totalfare = 0; decimal distanceunit = 0; decimal innerDistanceunit = 0; decimal outerDistanceunit = 0; int outerDist = totalDist - innerDist; decimal innerfare = (47m / (1000m / 300m)); decimal outerfare = (94m / (1000m / 300m)); if (innerDist > 0) { innerDistanceunit = (Convert.ToDecimal(innerDist) / 300m); outerDistanceunit = (Convert.ToDecimal(outerDist) / 300m); totalfare = (innerfare * innerDistanceunit) + (outerfare * outerDistanceunit); distanceunit = innerDistanceunit + outerDistanceunit; } else { distanceunit = (totalDist / 300m); totalfare = (outerfare * distanceunit); } mapn.MoveToRegion(MapSpan.FromPositions(list)); App.Current.MainPage.DisplayAlert("Price", "Total Distance : " + totalDist + " & Total Price : " + totalfare.ToString("F2") + "\nOuter Distance : " + outerDist + " @ Price : 94 cents" + "\nInner Distance : " + innerDist + " @ Price : 47 cents", "Ok"); }
public ShapesPage() { InitializeComponent(); Polyline polyline = null; Polygon polygon = null; Circle circle = null; // Polyline buttonAddPolyline.Clicked += (sender, e) => { polyline = new Polyline(); polyline.Positions.Add(new Position(40.77d, -73.93d)); polyline.Positions.Add(new Position(40.81d, -73.91d)); polyline.Positions.Add(new Position(40.83d, -73.87d)); polyline.IsClickable = true; polyline.StrokeColor = Color.Blue; polyline.StrokeWidth = 5f; polyline.Tag = "POLYLINE"; // Can set any object polyline.Clicked += Polyline_Clicked; map.Polylines.Add(polyline); ((Button)sender).IsEnabled = false; buttonRemovePolyline.IsEnabled = true; }; buttonRemovePolyline.Clicked += (sender, e) => { map.Polylines.Remove(polyline); polyline.Clicked -= Polyline_Clicked; polyline = null; ((Button)sender).IsEnabled = false; buttonAddPolyline.IsEnabled = true; }; buttonRemovePolyline.IsEnabled = false; // Polygon buttonAddPolygon.Clicked += (sender, e) => { polygon = new Polygon(); polygon.Positions.Add(new Position(40.85d, -73.96d)); polygon.Positions.Add(new Position(40.87d, -74.00d)); polygon.Positions.Add(new Position(40.78d, -74.06d)); polygon.Positions.Add(new Position(40.77d, -74.02d)); polygon.IsClickable = true; polygon.StrokeColor = Color.Green; polygon.StrokeWidth = 3f; polygon.FillColor = Color.FromRgba(255, 0, 0, 64); polygon.Tag = "POLYGON"; // Can set any object polygon.Clicked += Polygon_Clicked;; map.Polygons.Add(polygon); ((Button)sender).IsEnabled = false; buttonRemovePolygon.IsEnabled = true; }; buttonRemovePolygon.Clicked += (sender, e) => { map.Polygons.Remove(polygon); polygon.Clicked -= Polygon_Clicked; polygon = null; ((Button)sender).IsEnabled = false; buttonAddPolygon.IsEnabled = true; }; buttonRemovePolygon.IsEnabled = false; // Circle buttonAddCircle.Clicked += (sender, e) => { circle = new Circle(); circle.Center = new Position(40.72d, -73.89d); circle.Radius = Distance.FromMeters(3000f); circle.StrokeColor = Color.Purple; circle.StrokeWidth = 6f; circle.FillColor = Color.FromRgba(0, 0, 255, 32); circle.Tag = "CIRCLE"; // Can set any object map.Circles.Add(circle); ((Button)sender).IsEnabled = false; buttonRemoveCircle.IsEnabled = true; }; buttonRemoveCircle.Clicked += (sender, e) => { map.Circles.Remove(circle); circle = null; ((Button)sender).IsEnabled = false; buttonAddCircle.IsEnabled = true; }; buttonRemoveCircle.IsEnabled = false; }