Groot 6 mēneši atpakaļ
vecāks
revīzija
ec959766be

+ 0 - 97
ios/.symlinks/plugins/map_mapkit_ios/ios/Classes/Location/LocationManager.swift

@@ -1,97 +0,0 @@
-//
-//  LocationManager.swift
-//  Pods
-//
-//  Created by Groot on 2025/5/15.
-//
-
-import Foundation
-import CoreLocation
-import Flutter
-
-class LocationManager: NSObject {
-
-    static let shared = LocationManager()
-
-    private var locationUpdateEventChannel: FlutterEventChannel?
-    private var locationEventSink: FlutterEventSink?
-
-    private let locationManager = CLLocationManager()
-
-    var onLocationUpdate: ((CLLocation) -> Void)?
-
-    private override init() {
-        super.init()
-        locationManager.delegate = self
-        setup()
-    }
-
-    func start(withMessenger messenger: FlutterBinaryMessenger) -> Bool {
-        // permission detect
-        switch CLLocationManager.authorizationStatus() {
-        case .authorizedWhenInUse, .authorizedAlways:
-            locationManager.startUpdatingLocation()
-            setupMessenger(messenger: messenger)
-            return true
-        case .notDetermined:
-            locationManager.requestWhenInUseAuthorization()
-            return false
-        default:
-            print("LocationManager: authorizationStatus: \(CLLocationManager.authorizationStatus())")
-            return false
-        }
-    }
-
-    func stop() {
-        locationManager.stopUpdatingLocation()
-    }
-
-    func setupMessenger(messenger: FlutterBinaryMessenger) {
-        guard locationUpdateEventChannel == nil && locationEventSink == nil else { return }
-        locationUpdateEventChannel = FlutterEventChannel(name: MapKitConstans.locationUpdateEventChannelName, binaryMessenger: messenger)
-        locationUpdateEventChannel?.setStreamHandler(self)
-    }
-
-    func setup() {
-//        locationManager.allowsBackgroundLocationUpdates = true
-        locationManager.pausesLocationUpdatesAutomatically = false
-        locationManager.desiredAccuracy = kCLLocationAccuracyBest
-        locationManager.distanceFilter = 5.0
-        locationManager.activityType = .fitness
-        locationManager.showsBackgroundLocationIndicator = false
-    }
-}
-
-extension LocationManager: CLLocationManagerDelegate {
-    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
-        guard let location = locations.last else { return }
-        onLocationUpdate?(location)
-        if let eventSink = locationEventSink {
-            // 转换GPS坐标系到中国坐标系
-            let transformedCoordinate = location.coordinate.wgc84ToGCJ02
-            let atLocation = ATMapLocation.fromLocation(location: location)
-            atLocation.longitude = transformedCoordinate.longitude
-            atLocation.latitude = transformedCoordinate.latitude
-            
-            let jsonMessage = atLocation.toJson()
-            print(jsonMessage)
-            eventSink(jsonMessage)
-        }
-    }
-
-    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
-        print("LocationManager: didFailWithError: \(error)")
-    }
-}
-
-extension LocationManager: FlutterStreamHandler {
-    func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
-        locationEventSink = events
-        return nil
-    }
-
-    func onCancel(withArguments arguments: Any?) -> FlutterError? {
-        locationEventSink = nil
-        return nil
-    }
-}

+ 0 - 94
ios/.symlinks/plugins/map_mapkit_ios/ios/Classes/MapView/Extension/Coordinate+E.swift

@@ -1,94 +0,0 @@
-//
-//  Coordinate+E.swift
-//  Pods
-//
-//  Created by Groot on 2025/5/15.
-//
-
-import Foundation
-import CoreLocation
-
-extension CLLocationCoordinate2D {
-    /// 地球坐标 WGC-84 转为为火星坐标 GCJ-02(限中国境内)
-    /// - CLLocationManager 获取的是地球坐标,但地图上显示的需要火星坐标
-    /// - 通过 CLLocationManager 获取到中国境内地理坐标,若需要在地图上显示,则需要转换为火星坐标
-    var wgc84ToGCJ02: CLLocationCoordinate2D {
-        let earthRadius = 6378245.0
-        let gcj_ee = 0.00669342162296594323
-
-        var adjustedLatitude = transformedLatitude
-        var adjustedLongitude = transformedLongitude
-
-        let radLat = latitude / 180.0 * .pi
-        let magic: Double = {
-            let temp = sin(radLat)
-            let result = 1 - gcj_ee * temp * temp
-            return result
-        }()
-        let sqrtMagic = sqrt(magic)
-
-        adjustedLatitude = (adjustedLatitude * 180.0) / ((earthRadius * (1.0 - gcj_ee)) / (magic * sqrtMagic) * .pi)
-        adjustedLongitude = (adjustedLongitude * 180.0) / (earthRadius / sqrtMagic * cos(radLat) * .pi)
-
-        let result = CLLocationCoordinate2D(
-            latitude: latitude + adjustedLatitude,
-            longitude: longitude + adjustedLongitude
-        )
-
-        return result
-    }
-
-    var gcj02ToWGS84: CLLocationCoordinate2D {
-        let a = 6378245.0
-        let ee = 0.00669342162296594323
-        let gcjLat = latitude
-        let gcjLon = longitude
-        var dLat = transformLat(x: gcjLon - 105.0, y: gcjLat - 35.0)
-        var dLon = transformLon(x: gcjLon - 105.0, y: gcjLat - 35.0)
-        let radLat = gcjLat / 180.0 * Double.pi
-        var magic = sin(radLat)
-        magic = 1 - ee * magic * magic
-        let sqrtMagic = sqrt(magic)
-        dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * Double.pi)
-        dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * Double.pi)
-        let mgLat = gcjLat + dLat
-        let mgLon = gcjLon + dLon
-        return CLLocationCoordinate2D(latitude: gcjLat * 2 - mgLat, longitude: gcjLon * 2 - mgLon)
-    }
-    
-    private var transformedLatitude: Double {
-        let x = longitude - 105.0
-        let y = latitude - 35.0
-        var result = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x))
-        result += (20.0 * sin(6.0 * x * .pi) + 20.0 * sin(2.0 * x * .pi)) * 2.0 / 3.0
-        result += (20.0 * sin(y * .pi) + 40.0 * sin(y / 3.0 * .pi)) * 2.0 / 3.0
-        result += (160.0 * sin(y / 12.0 * .pi) + 320.0 * sin(y * .pi / 30.0)) * 2.0 / 3.0
-        return result
-    }
-
-    private var transformedLongitude: Double {
-        let x = longitude - 105.0
-        let y = latitude - 35.0
-        var result = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x))
-        result += (20.0 * sin(6.0 * x * .pi) + 20.0 * sin(2.0 * x * .pi)) * 2.0 / 3.0
-        result += (20.0 * sin(x * .pi) + 40.0 * sin(x / 3.0 * .pi)) * 2.0 / 3.0
-        result += (150.0 * sin(x / 12.0 * .pi) + 300.0 * sin(x / 30.0 * .pi)) * 2.0 / 3.0
-        return result
-    }
-
-    func transformLat(x: Double, y: Double) -> Double {
-        var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x))
-        ret += (20.0 * sin(6.0 * x * Double.pi) + 20.0 * sin(2.0 * x * Double.pi)) * 2.0 / 3.0
-        ret += (20.0 * sin(y * Double.pi) + 40.0 * sin(y / 3.0 * Double.pi)) * 2.0 / 3.0
-        ret += (160.0 * sin(y / 12.0 * Double.pi) + 320 * sin(y * Double.pi / 30.0)) * 2.0 / 3.0
-        return ret
-    }
-
-    func transformLon(x: Double, y: Double) -> Double {
-        var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x))
-        ret += (20.0 * sin(6.0 * x * Double.pi) + 20.0 * sin(2.0 * x * Double.pi)) * 2.0 / 3.0
-        ret += (20.0 * sin(x * Double.pi) + 40.0 * sin(x / 3.0 * Double.pi)) * 2.0 / 3.0
-        ret += (150.0 * sin(x / 12.0 * Double.pi) + 300.0 * sin(x / 30.0 * Double.pi)) * 2.0 / 3.0
-        return ret
-    }
-}

+ 1 - 1
plugins/map_mapkit_ios/ios/Classes/MapView/ViewModel/MapViewModel.swift

@@ -56,7 +56,7 @@ class MapViewModel: NSObject, ObservableObject, MapCapability {
         }
         
         self.markers = Array(markerDict.values)
-        print("Update Markers: --- \(markerDict["user_location"]?.markerType)")
+        print("Update Markers: --- \(markerDict["user_location"]?.markerType )")
         result(nil)
     }