Advertisement
Marcus1

idiotic error that should not happen but does

Apr 2nd, 2024 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.79 KB | None | 0 0
  1. //
  2. //  MapPolyline.swift
  3. //  playgroundProj
  4. //
  5. //  Created by Kraszni Marcell on 02/04/2024.
  6. //
  7.  
  8. import SwiftUI
  9. import MapKit
  10. import BottomSheet
  11.  
  12. struct MapPolyline: View {
  13.    
  14.     @State var polylinePositions: [CLLocationCoordinate2D] = []
  15.     @State var currentCoord = CLLocationCoordinate2D(latitude: 0, longitude: 0)
  16.     @State var bottomSheetPos: BottomSheetPosition = .dynamicBottom
  17.    
  18.     var body: some View {
  19.         Map { // The error shows on this line
  20.             MapPolyline(coordinates: polylinePositions) // The bug causer is this shitty line (can you tell I'm aggravated? btw the error is "No exact matches in call to initializer" if you forgot)
  21.             Marker("", systemImage: "mappin", coordinate: currentCoord)
  22.         }
  23.         .onMapCameraChange(frequency: .continuous, { context in
  24.             currentCoord = context.camera.centerCoordinate
  25.         })
  26.         .bottomSheet(bottomSheetPosition: $bottomSheetPos, switchablePositions: [.dynamicBottom, .dynamic]) {
  27.             HStack {
  28.                 Text("Current pos: \(currentCoord.latitude) \(currentCoord.longitude)")
  29.                     .bold()
  30.             }
  31.             .padding(.all)
  32.         } mainContent: {
  33.             VStack {
  34.                 Button(action: {
  35.                     polylinePositions.append(currentCoord)
  36.                 }, label: {
  37.                     HStack {
  38.                         Image(systemName: "mappin.and.ellipse")
  39.                         Text("Plot onto map")
  40.                     }
  41.                 })
  42.                 .buttonStyle(.bordered)
  43.             }
  44.             .padding(.all, 40)
  45.         }
  46.     }
  47. }
  48.  
  49. #Preview {
  50.     MapPolyline(polylinePositions: [CLLocationCoordinate2D(latitude: 1, longitude: 1.6543), CLLocationCoordinate2D(latitude: 1.6254, longitude: 1.6543)])
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement