You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
2.0 KiB
47 lines
2.0 KiB
import Flutter
|
|
import UIKit
|
|
import AMapNaviKit
|
|
|
|
public class AmapServicePlugin: NSObject, FlutterPlugin {
|
|
private static var channel: FlutterMethodChannel?
|
|
public static func register(with registrar: FlutterPluginRegistrar) {
|
|
let channel = FlutterMethodChannel(name: "com.yunqiinnovation.amap_service", binaryMessenger: registrar.messenger())
|
|
let instance = AmapServicePlugin()
|
|
// 必须先设置隐私合规
|
|
DispatchQueue.main.async {
|
|
// 2. API Key
|
|
AMapServices.shared()?.apiKey = "aa60a03be9f6531bcc64029e60f95d03"
|
|
AMapServices.shared().enableHTTPS = true
|
|
// 导航SDK隐私合规(如果使用导航功能)
|
|
AMapNaviManagerConfig.shared().updatePrivacyShow(.didShow, privacyInfo: .didContain)
|
|
AMapNaviManagerConfig.shared().updatePrivacyAgree(.didAgree)
|
|
// 3. 打印验证(调试用)
|
|
print("高德SDK初始化完成")
|
|
}
|
|
registrar.addMethodCallDelegate(instance, channel: channel)
|
|
self.channel = channel
|
|
}
|
|
|
|
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
|
switch call.method {
|
|
case "open":
|
|
print("liwei------------------ 打开导航页面")
|
|
if let args = call.arguments as? [String: Any],
|
|
let startpos = args["startpos"] as? String,
|
|
let endpos = args["endpos"] as? String,
|
|
let ntype = args["ntype"] as? String{
|
|
print("liwei------------------ 打开导航页面1 \(startpos) \(endpos)")
|
|
DispatchQueue.main.async {
|
|
let navVC = AmapViewController(startpos: startpos, endpos: endpos)
|
|
navVC.modalPresentationStyle = .fullScreen
|
|
UIApplication.shared.keyWindow?.rootViewController?.present(navVC, animated: true)
|
|
}
|
|
result(nil)
|
|
} else {
|
|
result(FlutterError(code: "INVALID_ARGUMENT", message: "Missing 'open' map", details: nil))
|
|
}
|
|
default:
|
|
result(FlutterMethodNotImplemented)
|
|
}
|
|
}
|
|
}
|
|
|