Bläddra i källkod

add location update call back

Groot 8 månader sedan
förälder
incheckning
fb98b809f7

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

@@ -0,0 +1,97 @@
+//
+//  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
+    }
+}

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

@@ -0,0 +1,94 @@
+//
+//  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
lib/sdk/map/map_helper.dart

@@ -13,7 +13,7 @@ class MapHelper {
 
   static Future<void> init() async {
     await FlutterMap.init();
-    _initLocationClient();
+    _initLocationClient(); 
   }
 
   static void _initLocationClient() {

+ 13 - 4
plugins/map/lib/src/entity/map_location.dart

@@ -42,13 +42,22 @@ class MapLocation implements Codable {
     return MapLocation(
       time: map['time'],
       address: map['address'],
-      latitude: map['latitude'],
-      longitude: map['longitude'],
+      latitude: _parseDouble(map['latitude']),
+      longitude: _parseDouble(map['longitude']),
       errorCode: map['errorCode'],
-      speed: map['speed'],
-      bearing: map['bearing'],
+      speed: _parseDouble(map['speed']),
+      bearing: _parseDouble(map['bearing']),
     );
   }
+  
+  // 将任何数值类型(包括整数)强制转换为double
+  static double _parseDouble(dynamic value) {
+    if (value == null) return 0.0;
+    if (value is double) return value;
+    if (value is int) return value.toDouble();
+    if (value is String) return double.tryParse(value) ?? 0.0;
+    return 0.0;
+  }
 
   @override
   String toString() {

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

@@ -0,0 +1,97 @@
+//
+//  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
+    }
+}

+ 55 - 0
plugins/map_mapkit_ios/ios/Classes/MapMapkitIosPlugin.swift

@@ -15,8 +15,63 @@ var currentPackage: MapSupportedPackage {
 }
 
 public class MapMapkitIosPlugin: NSObject, FlutterPlugin {
+
     public static func register(with registrar: FlutterPluginRegistrar) {
         let factory = MapFlutterViewFactory(messenger: registrar.messenger())
         registrar.register(factory, withId: MapKitConstans.mapViewId, gestureRecognizersBlockingPolicy: FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded)
+
+        // 注册通用方法通道
+        CommonMethodChannelHandler.shared.setBinaryMessenger(binaryMessenger: registrar.messenger())
+        let commonMethodChannel = FlutterMethodChannel(name: MapKitConstans.commonMethodChannelName, binaryMessenger: registrar.messenger())
+        commonMethodChannel.setMethodCallHandler { (call, result) in
+            CommonMethodChannelHandler.shared.handleMethodCall(call: call, result: result)
+        }
+    }
+
+    
+}
+
+class CommonMethodChannelHandler: NSObject {
+    private var binaryMessenger: FlutterBinaryMessenger?
+
+    static let shared = CommonMethodChannelHandler()
+
+    private override init() {
+        super.init()
+    }
+
+    func setBinaryMessenger(binaryMessenger: FlutterBinaryMessenger) {
+        self.binaryMessenger = binaryMessenger
+    }
+
+    func handleMethodCall(call: FlutterMethodCall, result: @escaping FlutterResult) {
+        handleCommonMethodCall(call: call, result: result)
+    }
+
+    private func handleCommonMethodCall(call: FlutterMethodCall, result: @escaping FlutterResult) {
+         guard let callMethod = CommonChannelMethod(rawValue: call.method) else {
+            result(FlutterMethodNotImplemented)
+            return
+        }
+
+        switch callMethod {
+        case .`init`:
+            result(true)
+            handleStartLocation(result: result)
+        case .getPlatformMapName:
+            result("map_mapkit_ios")
+        case .startLocation:
+            handleStartLocation(result: result)
+        }
+    }
+    
+    private func handleStartLocation(result: @escaping FlutterResult) {
+        guard let binaryMessenger else { return }
+        let isSuccess = LocationManager.shared.start(withMessenger: binaryMessenger)
+        if !isSuccess {
+            result(FlutterError(code: "LocationPermissionError", message: "Location permission not granted", details: nil))
+            return
+        }
     }
+    
 }

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

@@ -0,0 +1,94 @@
+//
+//  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/MapFlutterView.swift

@@ -35,7 +35,7 @@ class MapFlutterView: NSObject, FlutterPlatformView {
 
     init(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?, binaryMessenger messenger: FlutterBinaryMessenger) {
         contentView = UIView()
-        methodChannel = FlutterMethodChannel(name: MapKitConstans.methodChannelName + "\(viewId)", binaryMessenger: messenger)
+        methodChannel = FlutterMethodChannel(name: MapKitConstans.mapViewMethodChannelName + "\(viewId)", binaryMessenger: messenger)
         super.init()
         createMapView()
         setupMethodChannel()

+ 9 - 3
plugins/map_mapkit_ios/ios/Classes/MapView/Model/Constans.swift

@@ -8,9 +8,15 @@
 import Foundation
 
 struct MapKitConstans {
-    static let methodChannelName: String = "com.atmob.flutter_map/map_view_"
+    // 位置更新事件通道名称
+    static let locationUpdateEventChannelName: String = "atmob_map_location_event_channel"
     
-    static let mapViewId: String = "com.atmob.flutter.map"
+    // 通用方法通道
+    static let commonMethodChannelName: String = "atmob_map_method_channel"
 
-    static let userMarkerId: String = "com.atmob.flutter.user_marker"
+    // 地图相关通道名称
+    static let mapViewMethodChannelName: String = "com.atmob.flutter_map/map_view_"
+    
+    // 地图视图ID
+    static let mapViewId: String = "com.atmob.flutter.map"
 }

+ 1 - 5
plugins/map_mapkit_ios/ios/Classes/MapView/Model/MapProtocol.swift

@@ -21,8 +21,6 @@ protocol MapCapability {
 
     var polylines: [ATMapPolyline] { get set }
 
-    func initialize(args: [String: Any]?, result: @escaping FlutterResult)
-
     // 处理地图添加Marker
     func handleMapAddMarker(args: [[String: Any]]?, result: @escaping FlutterResult)
     
@@ -46,14 +44,12 @@ protocol MapCapability {
 
 extension MapCapability {
     func handleMethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
-        guard let callMethod = ChannelMethods(rawValue: call.method) else {
+        guard let callMethod = MapViewChannelMethod(rawValue: call.method) else {
             result(FlutterMethodNotImplemented)
             return
         }
         
         switch callMethod {
-        case .`init`:
-            initialize(args: call.arguments as? [String: Any], result: result)
         case .methodMapMoveCamera, .methodMapAnimateCamera:
             handleMapMoveCamera(args: call.arguments as? [String: Any], result: result)
         case .methodUpdateOrAddMarkers:

+ 32 - 0
plugins/map_mapkit_ios/ios/Classes/MapView/Model/MapViewChannelMethod.swift

@@ -0,0 +1,32 @@
+//
+//  ChannelMethods.swift
+//  Runner
+//
+//  Created by Groot on 2025/5/9.
+//
+
+import Foundation
+
+enum MapViewChannelMethod: String, CaseIterable {
+    // 地图相关方法名称
+    case methodMapMoveCamera = "map#moveCamera"
+    case methodMapAnimateCamera = "map#animateCamera" 
+    case methodMapClear = "map#clear"
+    
+    // 标记物相关方法名称
+    case methodUpdateOrAddMarkers = "marker#updateOrAddMarkers"
+    case methodReplaceAllMarkers = "marker#replaceAllMarkers"
+    case methodMarkerOnTap = "marker#onTap"
+    
+    // 轨迹纠偏
+    case methodQueryProcessedTrace = "trace#queryProcessedTrace"
+    
+    // polyline
+    case methodAddPolyline = "polyline#addPolyline"
+}
+
+enum CommonChannelMethod: String {
+    case `init` = "init"
+    case getPlatformMapName = "getPlatformMapName"
+    case startLocation = "startLocation"
+}

+ 32 - 0
plugins/map_mapkit_ios/ios/Classes/MapView/Model/Models.swift

@@ -109,6 +109,9 @@ class ATMapMarker: NSObject, Codable {
     required init(from decoder: Decoder) throws {
         let container = try decoder.container(keyedBy: CodingKeys.self)
         id = try container.decode(String.self, forKey: .id)
+        if id.isEmpty {
+            id = "user_location"
+        }
         if container.contains(.markerName) {
             markerName = try container.decodeIfPresent(String.self, forKey: .markerName)
         }
@@ -157,3 +160,32 @@ extension CLLocationCoordinate2D: Codable {
         try container.encode(longitude, forKey: .longitude)
     }
 }
+
+
+class ATMapLocation: NSObject, Codable {
+    var latitude: CGFloat?
+    var longitude: CGFloat?
+    var errorCode: Int = 0
+    var time: Int?
+    var bearing: CGFloat?
+    var speed: CGFloat?
+
+    init(latitude: CGFloat? = nil, longitude: CGFloat? = nil, time: Int? = nil, bearing: CGFloat? = nil, speed: CGFloat? = nil) {
+        self.latitude = latitude
+        self.longitude = longitude
+        self.time = time
+        self.bearing = bearing
+        self.speed = speed
+        super.init()
+    }
+
+    static func fromLocation(location: CLLocation) -> ATMapLocation {
+        return ATMapLocation(
+            latitude: CGFloat(location.coordinate.latitude), 
+            longitude: CGFloat(location.coordinate.longitude), 
+            time: Int(location.timestamp.timeIntervalSince1970), 
+            bearing: CGFloat(location.course), 
+            speed: CGFloat(location.speed)
+        )
+    }
+}

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

@@ -26,10 +26,6 @@ class MapViewModel: NSObject, ObservableObject, MapCapability {
     // 地图Polyline
     @Published var polylines: [ATMapPolyline] = []
 
-    func initialize(args: [String: Any]?, result: @escaping FlutterResult) {
-        result(true)
-        return
-    }
 
     // 处理地图移动
     func handleMapMoveCamera(args: [String: Any]?, result: @escaping FlutterResult) {
@@ -59,6 +55,7 @@ class MapViewModel: NSObject, ObservableObject, MapCapability {
         
         // 转换回数组
         self.markers = Array(markerDict.values)
+        print("Add Marker: -- \(markers)")
         result(nil)
     }
 
@@ -77,14 +74,14 @@ class MapViewModel: NSObject, ObservableObject, MapCapability {
             result(paramsDecodeError)
             return
         }
-
+        
         self.markers = markers
     }
 
     // 处理Marker点击事件
     func handleMarkerTap(marker: inout ATMapMarker) {
         toggleMarkerSelected(marker: &marker)
-        methodChannel?.invokeMethod(ChannelMethods.methodMarkerOnTap.rawValue, arguments: marker.toJson())
+        methodChannel?.invokeMethod(MapViewChannelMethod.methodMarkerOnTap.rawValue, arguments: marker.toJson())
     }
 
     // 处理地图添加Polyline