|
@@ -12,6 +12,7 @@ class BaiduMapManager: NSObject {
|
|
private static let _sharedInstance = BaiduMapManager()
|
|
private static let _sharedInstance = BaiduMapManager()
|
|
|
|
|
|
var completionBlock : BMKLocatingCompletionBlock?
|
|
var completionBlock : BMKLocatingCompletionBlock?
|
|
|
|
+ typealias LocationModelBlock = (_ locationModel: LocationModel) -> Void
|
|
|
|
|
|
class func getSharedInstance() -> BaiduMapManager {
|
|
class func getSharedInstance() -> BaiduMapManager {
|
|
return _sharedInstance
|
|
return _sharedInstance
|
|
@@ -21,23 +22,19 @@ class BaiduMapManager: NSObject {
|
|
|
|
|
|
} // 私有化init方法
|
|
} // 私有化init方法
|
|
|
|
|
|
- func initLocation() -> Void {
|
|
|
|
- initBlock()
|
|
|
|
-
|
|
|
|
- locationManager.requestLocation(withReGeocode: true, withNetworkState: true, completionBlock: self.completionBlock!)
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func initBlock() -> Void {
|
|
|
|
- completionBlock = { location, state, error in
|
|
|
|
|
|
+ func initLocation(locationModelBlock:@escaping LocationModelBlock) -> Void {
|
|
|
|
+ locationManager.requestLocation(withReGeocode: true, withNetworkState: true) { location, state, error in
|
|
|
|
|
|
|
|
+ var locationModel = LocationModel.getLocationModel()
|
|
if (error != nil) {
|
|
if (error != nil) {
|
|
LocationModel.setLocationModel(locationModel: LocationModel.getLocationModel()!)
|
|
LocationModel.setLocationModel(locationModel: LocationModel.getLocationModel()!)
|
|
|
|
+ locationModel = LocationModel.getLocationModel()
|
|
} else {
|
|
} else {
|
|
- let locationModel = LocationModel.init(latitude: String(describing: location!.location!.coordinate.latitude), longitude: String(describing: location!.location!.coordinate.longitude), cityCode: location!.rgcData!.cityCode ?? "", province: location!.rgcData!.province ?? "", city: location!.rgcData!.city ?? "", district: location!.rgcData!.district ?? "", street: location!.rgcData!.street ?? "", locationDescribe: location!.rgcData!.locationDescribe ?? "")
|
|
|
|
- LocationModel.setLocationModel(locationModel: locationModel)
|
|
|
|
|
|
+ let locationModel1 = LocationModel.init(latitude: String(describing: location!.location!.coordinate.latitude), longitude: String(describing: location!.location!.coordinate.longitude), cityCode: location!.rgcData!.cityCode ?? "", province: location!.rgcData!.province ?? "", city: location!.rgcData!.city ?? "", district: location!.rgcData!.district ?? "", street: location!.rgcData!.street ?? "", locationDescribe: location!.rgcData!.locationDescribe ?? "")
|
|
|
|
+ LocationModel.setLocationModel(locationModel: locationModel1)
|
|
|
|
+ locationModel = LocationModel.getLocationModel()
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ locationModelBlock(locationModel!)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -73,7 +70,6 @@ extension BaiduMapManager:BMKLocationManagerDelegate {
|
|
/// 当定位发生错误时,会调用代理的此方法。
|
|
/// 当定位发生错误时,会调用代理的此方法。
|
|
func bmkLocationManager(_ manager: BMKLocationManager, didFailWithError error: Error?) {
|
|
func bmkLocationManager(_ manager: BMKLocationManager, didFailWithError error: Error?) {
|
|
NXLLog("定位错误");
|
|
NXLLog("定位错误");
|
|
- LocationModel.setLocationModel(locationModel: LocationModel.getLocationModel()!)
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|