private void DrawElements() { if (((ExtendedMap)Element).MapPositionOption != Data.PositionInfo.PositionOption.Pin) { NativeMap.Clear(); _shapeCoordinates = ((ExtendedMap)Element).TempShapeCoordinates; if (_shapeCoordinates.Count > 0) { DrawPolygon(); } _routeCoordinates = ((ExtendedMap)Element).TempRouteCoordinates; if (_routeCoordinates.Count > 0) { DrawPolyline(); } } else { _polyline?.Remove(); _polygon?.Remove(); } }
public void DrawTripOnMap(string Json) { // TryCatch to handle any null Object exception. try { mPolyline.Remove(); PickupMarker.Remove(); destinationMarker.Remove(); } catch (Exception) { } var directionData = JsonConvert.DeserializeObject <DirectionParser>(Json); for (int i = 0; i < directionData.routes.Count; i++) { foreach (var point in RedissuePoints) { foreach (var waypoints in PolyUtil.Decode(directionData.routes[i].overview_polyline.points)) { if (Math.Abs(Convert.ToDouble(waypoints.Latitude) - Convert.ToDouble(point.Latitude)) <= 0.00001 && Math.Abs(Convert.ToDouble(waypoints.Longitude) - Convert.ToDouble(point.Longitude)) <= 0.00001) { issueWayPointCount[i] += 1; } } } } int routeIndex = issueWayPointCount.ToList().IndexOf(issueWayPointCount.Min()); //Decode Encoded route var Points = directionData.routes[routeIndex].overview_polyline.points; //enumerate through this line variable through for loop and //check for any points that matches for points contained in preloaded issues array var Line = PolyUtil.Decode(Points); ArrayList routeList = new ArrayList(); foreach (LatLng item in Line) { routeList.Add(item); } //Draw Polylines on map PolylineOptions polylineOptions = new PolylineOptions() .AddAll(routeList) .InvokeWidth(10) .InvokeColor(Color.BlueViolet) .InvokeStartCap(new SquareCap()) .InvokeEndCap(new RoundCap()) .InvokeJointType(JointType.Round) .Geodesic(true); mPolyline = googleMap.AddPolyline(polylineOptions); //Get first and last point LatLng firstpoint = Line[0]; LatLng lastpoint = Line[Line.Count - 1]; //Creating Marker Options MarkerOptions pickupMarkerOptions = new MarkerOptions(); pickupMarkerOptions.SetPosition(firstpoint); pickupMarkerOptions.SetTitle("Start Location"); BitmapDescriptor bitmapDescPickup = BitmapDescriptorFactory.FromResource(Resource.Drawable.starticon); pickupMarkerOptions.SetIcon(bitmapDescPickup); MarkerOptions destinationMarkerOptions = new MarkerOptions(); destinationMarkerOptions.SetPosition(lastpoint); destinationMarkerOptions.SetTitle("Destination"); BitmapDescriptor bitmapDescDestination = BitmapDescriptorFactory.FromResource(Resource.Drawable.destinationicon); destinationMarkerOptions.SetIcon(bitmapDescDestination); PickupMarker = googleMap.AddMarker(pickupMarkerOptions); destinationMarker = googleMap.AddMarker(destinationMarkerOptions); //Get Trip bounds double southlng = directionData.routes[0].bounds.southwest.lng; double southlat = directionData.routes[0].bounds.southwest.lat; double northlng = directionData.routes[0].bounds.northeast.lng; double northlat = directionData.routes[0].bounds.northeast.lat; LatLng southwest = new LatLng(southlat, southlng); LatLng northeast = new LatLng(northlat, northlng); LatLngBounds tripBounds = new LatLngBounds(southwest, northeast); googleMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(tripBounds, 4)); //googleMap.SetPadding(40, 70, 40, 70); }