public MapRoute(GoogleMap map, List<Station> stations) { _map = map; _mapRoutes = new List<Polyline>(); _mapStations = new List<Marker>(); // Choose color; Color color = Color.DodgerBlue; // Create polyline. var polyline = new PolylineOptions(); polyline.InvokeWidth(4f); polyline.InvokeColor(color); for (var i = 0; i < stations.Count; i++) { // Add points to polyline. var station = stations[i]; if (station != null && station.latitude != 0f && station.longitude != 0f) { var latlng = new Android.Gms.Maps.Model.LatLng(station.latitude, station.longitude); polyline.Add(latlng); // Create marker. var marker = new MarkerOptions(); marker.SetPosition(latlng); marker.SetTitle((i + 1) + ". " + station.postName); marker.Draggable(false); marker.SetSnippet("ul. " + station.street); _mapStations.Add(_map.AddMarker(marker)); } } // Add polyline to map. _mapRoutes.Add(_map.AddPolyline(polyline)); }
async void drawRoute(TravelData route, bool isOriginalRoute) { MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map); Android.Gms.Maps.GoogleMap map = mapFrag.Map; // DRAW THE ORIGIN POINT FIRST, THEN POLYLINE, ENDPOINT, POLYLINE, ENDPOINT... PolylineOptions polylineOptions = new PolylineOptions(); polylineOptions.Add(new LatLng(route.steps [0].originXY.latitude, route.steps [0].originXY.longitude)); Polyline polyline = map.AddPolyline(polylineOptions); if (isOriginalRoute) { polyline.Color = Resources.GetColor(Resource.Color.wallet_holo_blue_light); } else { polyline.Color = Resources.GetColor(Resource.Color.abc_search_url_text_pressed); } polyline.Width = 15; polyLines.Add(polyline); foreach (Step step in route.steps) { polylineOptions = new PolylineOptions(); List <GeoPoint> stepPoints = Algorithm.decodePoints(step.polyLine); foreach (GeoPoint point in stepPoints) { polylineOptions.Add(new LatLng(point.latitude, point.longitude)); } polylineOptions.Add(new LatLng(step.endpointXY.latitude, step.endpointXY.longitude)); polyline = map.AddPolyline(polylineOptions); if (isOriginalRoute) { polyline.Color = Resources.GetColor(Resource.Color.wallet_holo_blue_light); } else { polyline.Color = Resources.GetColor(Resource.Color.abc_search_url_text_pressed); } polyline.Width = 15; polyLines.Add(polyline); } }
public void OnMapReady (GoogleMap googleMap) { map = googleMap; var polylineOptions = new PolylineOptions (); polylineOptions.InvokeColor (0x66FF0000); foreach (var position in routeCoordinates) { polylineOptions.Add (new LatLng (position.Latitude, position.Longitude)); } map.AddPolyline (polylineOptions); }
private void AddPolyline(Polyline polyline) { PolylineOptions options = new PolylineOptions(); options.Add(polyline.Points.Select(p => new LatLng(p.Latitude, p.Longitude)).ToArray()); if (polyline.ZIndex.HasValue) { options.InvokeZIndex(polyline.ZIndex.Value); } if (polyline.StrokeColor != null) { options.InvokeColor(Graphics.Color.ParseColor(polyline.StrokeColor)); } if (polyline.StrokeWidth.HasValue) { options.InvokeWidth(polyline.StrokeWidth.Value); } googleMap.AddPolyline(options); }
public static PolylineAdv Add(GoogleMap map, PolylineOptions op) { var polyline = new PolylineAdv(map, op); var idxStart = 0; while (idxStart < op.Points.Count) { using (var options = CloneOptions(op)) { for (var i = idxStart; i < Math.Min(idxStart + PolylineSegmentLength + 1, op.Points.Count); i++) { options.Add(op.Points[i]); } polyline._polylines.Add(map.AddPolyline(options)); } idxStart += PolylineSegmentLength; } return polyline; }
private void SetupMapIfNeeded() { if (_map == null) { _map = _mapFragment.Map; if (_map != null) { var centerPoint = new LatLng (Station.TroncalRouteCenter.Y, Station.TroncalRouteCenter.X); Activity.RunOnUiThread (delegate{ _map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(centerPoint,15.0f)); _map.MyLocationEnabled = true; }); stations = stationRepository.Stations; Activity.RunOnUiThread (delegate{ foreach(var station in stations){ var location = new LatLng(station.Latitude, station.Longitude); var stationImageId = Resources.GetIdentifier( station.ImageFilename().ToLower(), "drawable", Activity.PackageName); var originalStationBitmap = BitmapFactory.DecodeResource(Resources, stationImageId); var scale = Resources.DisplayMetrics.Density; var pixels = 35; var stationBitmap = Bitmap.CreateScaledBitmap(originalStationBitmap, (int) (pixels * scale + 0.5f), (int) (pixels * scale + 0.5f), false); MarkerOptions markerOptions = new MarkerOptions() .SetPosition(location) .InvokeIcon(BitmapDescriptorFactory.FromBitmap(stationBitmap)) .SetTitle(station.Name); _map.AddMarker(markerOptions); } var polylineOptions = new PolylineOptions(); polylineOptions.InvokeWidth(5.0f); polylineOptions.InvokeColor(Color.Black); foreach(var point in Station.TroncalRoutePath){ polylineOptions.Add(new LatLng(point.Y, point.X)); } _map.AddPolyline(polylineOptions); }); } } }
public MapRoute(GoogleMap map, ServerResponse.ResponseRoute[] responseRoutes) { var numberOfRoutes = responseRoutes.Length * 2 - 1; _map = map; _mapRoutes = new List<Polyline>(); _mapStations = new List<Marker>(); var l = 1; for (var i = 0; i < numberOfRoutes; i++) { // Create new partial route. if (i % 2 == 0) { // Choose color; Color color = Color.DodgerBlue; // Create polyline. var polyline = new PolylineOptions(); polyline.InvokeWidth(4f); polyline.InvokeColor(color); // Add points to polyline. int k = i / 2; ServerResponse.ResponseRoute responseRoute = responseRoutes[k]; for (var j = 0; j < responseRoute.pointsId.Length; j++) { string stationId = responseRoute.pointsId[j]; Station station = App.Database.GetStationById(stationId); if (station != null && station.latitude != 0f && station.longitude != 0f) { var latlng = new Android.Gms.Maps.Model.LatLng(station.latitude, station.longitude); polyline.Add(latlng); // Create marker. var marker = new MarkerOptions(); marker.SetPosition(latlng); marker.SetTitle(l++ + ". " + station.postName); marker.Draggable(false); marker.SetSnippet("ul. " + station.street + "\n"+ "linia: " + responseRoute.variantId); _mapStations.Add(_map.AddMarker(marker)); } } // Add polyline to map. _mapRoutes.Add(_map.AddPolyline(polyline)); } // Create connection between two routes. else { // Choose color; Color color = Color.LightSkyBlue; // Create polyline. PolylineOptions polyline = new PolylineOptions(); polyline.InvokeWidth(3f); polyline.InvokeColor(color); // Add points to polyline (closest, non 0f points). // Last point from previous route. int k = i / 2; for (var j = 0; j < responseRoutes[k].pointsId.Length; j++) { string prevStationId = responseRoutes[k].pointsId[responseRoutes[k].pointsId.Length - 1 - j]; Station prevStation = App.Database.GetStationById(prevStationId); if (prevStation != null && prevStation.latitude != 0f && prevStation.longitude != 0f) { polyline.Add(new Android.Gms.Maps.Model.LatLng(prevStation.latitude, prevStation.longitude)); break; } } // 1st point from next route. k++; for (var j = 0; j < responseRoutes[k].pointsId.Length; j++) { string nextStationId = responseRoutes[k].pointsId[j]; Station nextStation = App.Database.GetStationById(nextStationId); if (nextStation != null && nextStation.latitude != 0f && nextStation.longitude != 0f) { polyline.Add(new Android.Gms.Maps.Model.LatLng(nextStation.latitude, nextStation.longitude)); break; } } // Add polyline to map. _mapRoutes.Add(_map.AddPolyline(polyline)); } } }