Browse Source

百度定位,高德定位设置完成

nanxinlin 6 years ago
parent
commit
1e4501f641

+ 1 - 1
RainbowPlanet/Podfile

@@ -73,7 +73,7 @@ target 'RainbowPlanet' do
   pod 'BMKLocationKit'
 
   #=====================高德地图===========
-  #  #百度地图定位SDK
+  #高德地图定位SDK
   pod 'AMapLocation'
 
 

+ 9 - 5
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -8,7 +8,6 @@
 
 /* Begin PBXBuildFile section */
 		0A110C4CD931995B8E8BF7C5 /* Pods_RainbowPlanet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D469F6C3768252BCB7001EDD /* Pods_RainbowPlanet.framework */; };
-		A72A726622321DBD00B21995 /* BaiduMapManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A726222321DBD00B21995 /* BaiduMapManager.swift */; };
 		A72A726722321DBD00B21995 /* LocationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A726322321DBD00B21995 /* LocationModel.swift */; };
 		A72A726822321DBD00B21995 /* UMManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A726522321DBD00B21995 /* UMManager.swift */; };
 		A72A72A222321DE000B21995 /* LBXScanNetAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A726A22321DDE00B21995 /* LBXScanNetAnimation.swift */; };
@@ -80,6 +79,8 @@
 		A75414FD224B5F28002480B5 /* PasswordLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75414FB224B5F28002480B5 /* PasswordLoginViewController.swift */; };
 		A75414FE224B5F28002480B5 /* PasswordLoginViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A75414FC224B5F28002480B5 /* PasswordLoginViewController.xib */; };
 		A7541500224BC02F002480B5 /* AMapManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75414FF224BC02F002480B5 /* AMapManager.swift */; };
+		A7541502224C5ECB002480B5 /* BaiduMapManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7541501224C5ECA002480B5 /* BaiduMapManager.swift */; };
+		A7541504224C609A002480B5 /* AMapLocationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7541503224C609A002480B5 /* AMapLocationModel.swift */; };
 		A76390EB2248E27A0067EEE0 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A76390EA2248E27A0067EEE0 /* UserNotifications.framework */; };
 		A775CBFE2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A775CBFD2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift */; };
 		A775CC00223774A300EBDCF8 /* ShoppingMallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A775CBFF223774A300EBDCF8 /* ShoppingMallView.swift */; };
@@ -148,7 +149,6 @@
 		57C497E128081597F165C771 /* Pods-RainbowPlanet.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RainbowPlanet.release.xcconfig"; path = "Pods/Target Support Files/Pods-RainbowPlanet/Pods-RainbowPlanet.release.xcconfig"; sourceTree = "<group>"; };
 		88DF1EFD2E202DA7C627E8A7 /* Pods_RainbowPlanetUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RainbowPlanetUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		A72A726022321D3400B21995 /* RainbowPlanet-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RainbowPlanet-Bridging-Header.h"; sourceTree = "<group>"; };
-		A72A726222321DBD00B21995 /* BaiduMapManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaiduMapManager.swift; sourceTree = "<group>"; };
 		A72A726322321DBD00B21995 /* LocationModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationModel.swift; sourceTree = "<group>"; };
 		A72A726522321DBD00B21995 /* UMManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UMManager.swift; sourceTree = "<group>"; };
 		A72A726A22321DDE00B21995 /* LBXScanNetAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LBXScanNetAnimation.swift; sourceTree = "<group>"; };
@@ -222,6 +222,8 @@
 		A75414FB224B5F28002480B5 /* PasswordLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordLoginViewController.swift; sourceTree = "<group>"; };
 		A75414FC224B5F28002480B5 /* PasswordLoginViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PasswordLoginViewController.xib; sourceTree = "<group>"; };
 		A75414FF224BC02F002480B5 /* AMapManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AMapManager.swift; sourceTree = "<group>"; };
+		A7541501224C5ECA002480B5 /* BaiduMapManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaiduMapManager.swift; sourceTree = "<group>"; };
+		A7541503224C609A002480B5 /* AMapLocationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AMapLocationModel.swift; sourceTree = "<group>"; };
 		A76390EA2248E27A0067EEE0 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
 		A775CBFD2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingMallNavigationBarView.swift; sourceTree = "<group>"; };
 		A775CBFF223774A300EBDCF8 /* ShoppingMallView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingMallView.swift; sourceTree = "<group>"; };
@@ -379,9 +381,10 @@
 		A72A726122321DBD00B21995 /* MapManager */ = {
 			isa = PBXGroup;
 			children = (
-				A72A726222321DBD00B21995 /* BaiduMapManager.swift */,
-				A75414FF224BC02F002480B5 /* AMapManager.swift */,
+				A7541501224C5ECA002480B5 /* BaiduMapManager.swift */,
 				A72A726322321DBD00B21995 /* LocationModel.swift */,
+				A75414FF224BC02F002480B5 /* AMapManager.swift */,
+				A7541503224C609A002480B5 /* AMapLocationModel.swift */,
 			);
 			path = MapManager;
 			sourceTree = "<group>";
@@ -1322,13 +1325,13 @@
 				A7778CB82244E97A00C7C47A /* BindPhoneNumberViewController.swift in Sources */,
 				A72A72D322321E2700B21995 /* CacheMacro.swift in Sources */,
 				A72A72A422321DE000B21995 /* LBXScanViewController.swift in Sources */,
+				A7541504224C609A002480B5 /* AMapLocationModel.swift in Sources */,
 				A77F2CB52232010F001BD3F6 /* ShoppingMallViewController.swift in Sources */,
 				A75414F7224B4C1B002480B5 /* VerificationPhoneViewController.swift in Sources */,
 				A77F2CC3223203BA001BD3F6 /* AppDelegate+Window.swift in Sources */,
 				A72A72B022321DE000B21995 /* CGView.swift in Sources */,
 				A72A73142232475E00B21995 /* AlipayManager.swift in Sources */,
 				A72A72D522321E2700B21995 /* ColorMacro.swift in Sources */,
-				A72A726622321DBD00B21995 /* BaiduMapManager.swift in Sources */,
 				A72A737E2233966800B21995 /* RootInfoModel.swift in Sources */,
 				A72A7333223256E100B21995 /* PayManager.swift in Sources */,
 				A775CC00223774A300EBDCF8 /* ShoppingMallView.swift in Sources */,
@@ -1377,6 +1380,7 @@
 				A72A72D222321E2700B21995 /* Common.swift in Sources */,
 				A72A72B522321DE000B21995 /* Extension+UITextView.swift in Sources */,
 				A72A733722325EED00B21995 /* AlipayResultModel.swift in Sources */,
+				A7541502224C5ECB002480B5 /* BaiduMapManager.swift in Sources */,
 				A77F2C9C2231FDCF001BD3F6 /* BaseView.swift in Sources */,
 				A72A7388223396CB00B21995 /* ApiMacro.swift in Sources */,
 				A72A72B922321DE000B21995 /* Extension+Array.swift in Sources */,

+ 0 - 1
RainbowPlanet/RainbowPlanet/AppDelegate/AppDelegate+HandleOpen.swift

@@ -66,4 +66,3 @@ extension AppDelegate {
         NXLLog(tokenString)
     }
 }
-

+ 4 - 4
RainbowPlanet/RainbowPlanet/AppDelegate/AppDelegate.swift

@@ -15,8 +15,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 
 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
-        //初始化高德定位
-        AMapManager.shared().initAMap()
+        //初始化高德地图
+//        AMapManager.shared().initAMap()
+        //初始化百度地图
+        BaiduMapManager.shared().initBaiduMap()
         //初始化窗口
         initWindow()
         //初始化友盟
@@ -26,6 +28,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         return true
     }
 
-
 }
-

+ 1 - 1
RainbowPlanet/RainbowPlanet/Define/ThirdPartyMacro.swift

@@ -29,7 +29,7 @@ let kWeiboAppSecret  = "79d36bfe6b75638ece14d5d852e785c4"
 let kBaiduMapAppKey  = "v7wFjrAQdlaBVC50CjwuRESC3Lu0xkhj"
 
 //MARK: - 高德地图
-let kAMapAppKey  = ""
+let kAMapAppKey  = "daae215db1937220769796457b8d0327"
 
 
 //MARK: - aliPay

+ 121 - 0
RainbowPlanet/RainbowPlanet/Manager/MapManager/AMapLocationModel.swift

@@ -0,0 +1,121 @@
+//
+//  AMapLocationModel.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/3/28.
+//  Copyright © 2019 南鑫林. All rights reserved.
+//
+
+import UIKit
+
+class AMapLocationModel: NSObject,NSCoding {
+
+    private static let _sharedInstance = AMapLocationModel()
+
+    override init() {} // 私有化init方法
+
+    class func shared() -> AMapLocationModel {
+        return _sharedInstance
+    }
+
+    /// 纬度
+    var latitude : String = "34.20207981"
+
+    /// 经度
+    var longitude : String = "108.95623806"
+
+    /// 国家
+    var country : String = "中国"
+
+    /// 省份
+    var province : String = "陕西省"
+
+    /// 市
+    var city : String = "西安市"
+
+    /// 区/县
+    var district : String = "雁塔区"
+
+    /// 街道
+    var street : String = "翠华南路"
+
+    /// 详细描述
+    var poiName : String = "华侨城天鹅堡4期"
+
+    /// AOIName
+    var aoiName : String = ""
+
+    /// 编号
+    var number : String = "62号"
+
+    /// 城市Code
+    var citycode : String = "029"
+
+    /// adcode
+    var adcode : String = "610113"
+
+    /// 地址格式化
+    var formattedAddress : String = "陕西省西安市雁塔区翠华南路靠近华侨城天鹅堡4期"
+
+    /// 归档
+    ///
+    /// - Parameter aCoder: 归档值
+    func encode(with aCoder: NSCoder) {
+        aCoder.encode(self.latitude, forKey:"latitude")
+        aCoder.encode(self.longitude, forKey:"longitude")
+        aCoder.encode(self.country, forKey:"country")
+        aCoder.encode(self.province, forKey:"province")
+        aCoder.encode(self.city, forKey:"city")
+        aCoder.encode(self.district, forKey:"district")
+        aCoder.encode(self.street, forKey:"street")
+        aCoder.encode(self.poiName, forKey:"poiName")
+        aCoder.encode(self.aoiName, forKey:"aoiName")
+        aCoder.encode(self.number, forKey:"number")
+        aCoder.encode(self.citycode, forKey:"citycode")
+        aCoder.encode(self.adcode, forKey:"adcode")
+        aCoder.encode(self.formattedAddress, forKey:"formattedAddress")
+    }
+    
+    /// 反归档
+    ///
+    /// - Parameter decoder: 反编码值
+    required init?(coder aDecoder: NSCoder) {
+        self.latitude = aDecoder.decodeObject(forKey: "latitude") as! String
+        self.longitude = aDecoder.decodeObject(forKey: "longitude") as! String
+        self.country = aDecoder.decodeObject(forKey: "country") as! String
+        self.province = aDecoder.decodeObject(forKey: "province") as! String
+        self.city = aDecoder.decodeObject(forKey: "city") as! String
+        self.district = aDecoder.decodeObject(forKey: "district") as! String
+        self.street = aDecoder.decodeObject(forKey: "street") as! String
+        self.poiName = aDecoder.decodeObject(forKey: "poiName") as! String
+        self.aoiName = aDecoder.decodeObject(forKey: "aoiName") as! String
+        self.number = aDecoder.decodeObject(forKey: "number") as! String
+        self.citycode = aDecoder.decodeObject(forKey: "citycode") as! String
+        self.adcode = aDecoder.decodeObject(forKey: "adcode") as! String
+        self.formattedAddress = aDecoder.decodeObject(forKey: "formattedAddress") as! String
+    }
+
+    /// 获取定位信息
+    ///
+    /// - Returns: 定位模型
+    public func getLocationModel() -> AMapLocationModel? {
+        //自定义对象读取
+        let modelData = UserDefaults.standard.data(forKey: "AMapLocationModel")
+        var locationModel = AMapLocationModel()
+        if modelData != nil {
+            locationModel = NSKeyedUnarchiver.unarchiveObject(with: modelData!) as! AMapLocationModel
+        }
+        return locationModel
+    }
+
+    /// 存储定位信息
+    ///
+    /// - Parameter locationModel: 定位模型
+    public func setLocationModel(locationModel:AMapLocationModel) -> Void {
+        //实例对象转换成Data
+        let modelData = NSKeyedArchiver.archivedData(withRootObject: locationModel)
+        //存储Data对象
+        UserDefaults.standard.set(modelData, forKey: "AMapLocationModel")
+    }
+
+}

+ 66 - 22
RainbowPlanet/RainbowPlanet/Manager/MapManager/AMapManager.swift

@@ -13,6 +13,21 @@ class AMapManager: NSObject {
 
     private override init() {} // 私有化init方法
 
+    typealias LocationModelBlock = (_ locationModel: AMapLocationModel) -> Void
+
+    class func shared() -> AMapManager {
+        return _sharedInstance
+    }
+
+    var locationModel = AMapLocationModel.shared().getLocationModel()
+
+    public func initAMap() -> Void {
+        AMapServices.shared().apiKey = kAMapAppKey
+        requestLocation(isSoughSingleLocation: true, isAccurateSingleLocation: false) { [weak self] (locationModel) in
+            self?.locationModel = locationModel
+        }
+    }
+
     private lazy var locationManager: AMapLocationManager = {
         // 注意: locationManager为该类的属性
         let locationManager = AMapLocationManager()
@@ -38,20 +53,21 @@ class AMapManager: NSObject {
         locationManager.locationTimeout = 10
         //   逆地理请求超时时间,最低2s,此处设置为10s
         locationManager.reGeocodeTimeout = 10
+        locationManager.distanceFilter = 10
     }
 
+    private func isSoughAccurateSingle(isSoughSingleLocation:Bool = false, isAccurateSingleLocation:Bool = false)  {
 
-    typealias LocationModelBlock = (_ locationModel: LocationModel) -> Void
-
-    class func shared() -> AMapManager {
-        return _sharedInstance
-    }
-
-    public func initAMap() -> Void {
-        AMapServices.shared().apiKey = kAMapAppKey
-        requestLocation(isSoughSingleLocation: true) { (locationModel) in
+        //粗单次定位
+        if isSoughSingleLocation {
+            soughSingleLocation()
+        }
 
+        //精准单次定位
+        if isAccurateSingleLocation {
+            soughSingleLocation()
         }
+        
     }
 
     /// 请求单次定位
@@ -60,7 +76,7 @@ class AMapManager: NSObject {
     ///   - isSoughSingleLocation:
     ///   - isAccurateSingleLocation: 粗单次定位 默认不调用
     ///   - locationModelBlock: 精准单次定位 默认不调用
-    public func requestLocation(isSoughSingleLocation:Bool = false, isAccurateSingleLocation:Bool = false, locationModelBlock:LocationModelBlock) {
+    public func requestLocation(isSoughSingleLocation:Bool = false, isAccurateSingleLocation:Bool = false, locationModelBlock:@escaping LocationModelBlock) {
 
 
         //粗单次定位
@@ -73,7 +89,7 @@ class AMapManager: NSObject {
             soughSingleLocation()
         }
 
-        locationManager.requestLocation(withReGeocode: true, completionBlock: {(location: CLLocation?, reGeocode: AMapLocationReGeocode?, error: Error?) in
+        locationManager.requestLocation(withReGeocode: true, completionBlock: {[weak self] (location: CLLocation?, reGeocode: AMapLocationReGeocode?, error: Error?) in
 
             if let error = error {
                 let error = error as NSError
@@ -95,13 +111,8 @@ class AMapManager: NSObject {
                 }
             }
 
-            if let location = location {
-                NXLLog("location:\(location)")
-            }
-
-            if let reGeocode = reGeocode {
-                NXLLog("reGeocode:\(reGeocode)")
-            }
+            self?.locationModel = self?.savelocationModel(location: location, reGeocode: reGeocode)
+            locationModelBlock(self?.locationModel ?? AMapLocationModel.shared().getLocationModel()!)
         })
     }
 
@@ -141,6 +152,42 @@ class AMapManager: NSObject {
         locationManager.stopUpdatingLocation()
     }
 
+    public func savelocationModel(location: CLLocation!, reGeocode: AMapLocationReGeocode?) -> AMapLocationModel  {
+        if let location = location {
+            NXLLog("location:\(location)")
+            locationModel?.longitude = String(describing: location.coordinate.longitude)
+            locationModel?.latitude = String(describing: location.coordinate.latitude)
+        }
+
+        if let reGeocode = reGeocode {
+            NXLLog("reGeocode:\(reGeocode)")
+            /// 国家
+            locationModel?.country = reGeocode.country ?? ""
+            /// 省份
+            locationModel?.province = reGeocode.province ?? ""
+            /// 市
+            locationModel?.city = reGeocode.city ?? ""
+            /// 区/县
+            locationModel?.district = reGeocode.district ?? ""
+            /// 街道
+            locationModel?.street = reGeocode.street ?? ""
+            /// 详细描述
+            locationModel?.poiName = reGeocode.poiName ?? ""
+            /// AOIName
+            locationModel?.aoiName = reGeocode.aoiName ?? ""
+            /// 编号
+            locationModel?.number = reGeocode.number ?? ""
+            /// 城市Code
+            locationModel?.citycode = reGeocode.citycode ?? ""
+            /// adcode
+            locationModel?.adcode = reGeocode.adcode ?? ""
+            /// 地址格式化
+            locationModel?.formattedAddress = reGeocode.formattedAddress ?? ""
+        }
+        AMapLocationModel.shared().setLocationModel(locationModel: locationModel!)
+        return locationModel!
+    }
+
 }
 
 // MARK: - 持续定位/后台定位
@@ -148,10 +195,7 @@ extension AMapManager: AMapLocationManagerDelegate {
 
     func amapLocationManager(_ manager: AMapLocationManager!, didUpdate location: CLLocation!, reGeocode: AMapLocationReGeocode?) {
         NXLLog("location:{lat:\(location.coordinate.latitude); lon:\(location.coordinate.longitude); accuracy:\(location.horizontalAccuracy);};");
-
-        if let reGeocode = reGeocode {
-            NXLLog("reGeocode:\(reGeocode)")
-        }
+        locationModel = savelocationModel(location: location, reGeocode: reGeocode)
     }
 
 }

+ 52 - 11
RainbowPlanet/RainbowPlanet/Manager/MapManager/BaiduMapManager.swift

@@ -18,27 +18,68 @@ public class BaiduMapManager: NSObject {
         return _sharedInstance
     }
 
-    var completionBlock : BMKLocatingCompletionBlock?
     typealias LocationModelBlock = (_ locationModel: LocationModel) -> Void
 
+    var locationModel = LocationModel.shared().getLocationModel()
 
     public func initBaiduMap() -> Void {
         BMKLocationAuth.sharedInstance()?.checkPermision(withKey: kBaiduMapAppKey, authDelegate: self)
+        initLocation()
     }
-    
+
+    /// 单次定位
+    func initLocation() {
+        locationManager.requestLocation(withReGeocode: true, withNetworkState: true) { [weak self] location, state, error in
+            if (error != nil) {
+                LocationModel.shared().setLocationModel(locationModel: (self?.locationModel!)!)
+                return
+            } else {
+                if let location = location {
+                    if let location = location.location {
+                        self?.locationModel?.latitude = String(describing: location.coordinate.latitude)
+                        self?.locationModel?.longitude = String(describing: location.coordinate.longitude)
+                    }
+                    if let rgcData = location.rgcData {
+                        self?.locationModel?.cityCode = rgcData.cityCode ?? ""
+                        self?.locationModel?.province = rgcData.province ?? ""
+                        self?.locationModel?.city = rgcData.city ?? ""
+                        self?.locationModel?.district = rgcData.district ?? ""
+                        self?.locationModel?.street = rgcData.street ?? ""
+                        self?.locationModel?.locationDescribe = rgcData.locationDescribe ?? ""
+                    }
+                    LocationModel.shared().setLocationModel(locationModel: (self?.locationModel!)!)
+                }
+            }
+            self?.locationModel = LocationModel.shared().getLocationModel()
+        }
+    }
+
+    /// 单次定位
     func initLocation(locationModelBlock:@escaping LocationModelBlock) -> Void {
-        locationManager.requestLocation(withReGeocode: true, withNetworkState: true) { location, state, error in
 
-            var locationModel = LocationModel.getLocationModel()
+        locationManager.requestLocation(withReGeocode: true, withNetworkState: true) { [weak self] location, state, error in
             if (error != nil) {
-                LocationModel.setLocationModel(locationModel: LocationModel.getLocationModel()!)
-                locationModel = LocationModel.getLocationModel()
+                LocationModel.shared().setLocationModel(locationModel:(self?.locationModel!)!)
+                return
             } else {
-                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()
+                if let location = location {
+                    if let location = location.location {
+                        self?.locationModel?.latitude = String(describing: location.coordinate.latitude)
+                        self?.locationModel?.longitude = String(describing: location.coordinate.longitude)
+                    }
+                    if let rgcData = location.rgcData {
+                        self?.locationModel?.cityCode = rgcData.cityCode ?? ""
+                        self?.locationModel?.province = rgcData.province ?? ""
+                        self?.locationModel?.city = rgcData.city ?? ""
+                        self?.locationModel?.district = rgcData.district ?? ""
+                        self?.locationModel?.street = rgcData.street ?? ""
+                        self?.locationModel?.locationDescribe = rgcData.locationDescribe ?? ""
+                    }
+                    LocationModel.shared().setLocationModel(locationModel:  (self?.locationModel!)!)
+                }
             }
-            locationModelBlock(locationModel!)
+            self?.locationModel = LocationModel.shared().getLocationModel()
+            locationModelBlock((self?.locationModel!)!)
         }
     }
 
@@ -100,7 +141,7 @@ extension BaiduMapManager: BMKLocationAuthDelegate {
             }
         } else {
             NXLLog("授权失败 \(iError)");
-            LocationModel.setLocationModel(locationModel: LocationModel.getLocationModel()!)
+            LocationModel.shared().setLocationModel(locationModel: locationModel!)
         }
     }
 }

+ 63 - 56
RainbowPlanet/RainbowPlanet/Manager/MapManager/LocationModel.swift

@@ -10,57 +10,57 @@ import UIKit
 
 class LocationModel: NSObject,NSCoding {
 
-    /// 纬度
-    var latitude : String = ""
-    /// 经度
-    var longitude : String = ""
-    /// 城市code
-    var cityCode : String = ""
-    /// 省
-    var province : String = ""
-    /// 城市
-    var city : String = ""
-    /// 区
-    var district : String = ""
-    /// 街道
-    var street : String = ""
-    /// 详细描述
-    var locationDescribe : String = ""
+    private static let _sharedInstance = LocationModel()
 
+    override init() {} // 私有化init方法
 
-    /// 构造方法
-    ///
-    /// - Parameters:
-    ///   - latitude: 纬度
-    ///   - longitude: 经度
-    ///   - city: 城市
-    ///   - cityCode: 城市code
-    required init(latitude:String="", longitude:String="",cityCode:String="",province:String="",city:String="",district : String = "",street : String = "",locationDescribe : String = "" ) {
-        self.latitude = latitude
-        self.longitude = longitude
-        self.cityCode = cityCode
-        self.province = province
-        self.city = city
-        self.district = district
-        self.street = street
-        self.locationDescribe = locationDescribe
+    class func shared() -> LocationModel {
+        return _sharedInstance
     }
 
-
+    /// 纬度
+    var latitude : String = "34.20840377740726"
+    /// 经度
+    var longitude : String = "108.96265686107972"
+    ///国家名字属性
+    var country = "中国"
+    ///国家编码属性
+    var countryCode = "0"
+    ///省份名字属性
+    var province = "陕西省"
+    ///城市名字属性
+    var city = "西安市"
+    ///区名字属性
+    var district = "雁塔区"
+    ///街道名字属性
+    var street = "翠华路"
+    ///街道号码属性
+    var streetNumber = "0"
+    ///城市编码属性
+    var cityCode = "233"
+    ///行政区划编码属性
+    var adCode = "610113"
+    ///位置语义化结果的定位点在什么地方周围的描述信息
+    var locationDescribe = "在西安北大科技园曲江创客大街园区附近"
+    
     /// 反归档
     ///
     /// - Parameter decoder: 反编码值
-    required init(coder decoder: NSCoder) {
-        self.latitude = decoder.decodeObject(forKey: "latitude") as? String ?? ""
-        self.longitude = decoder.decodeObject(forKey: "longitude") as? String ?? ""
-        self.cityCode = decoder.decodeObject(forKey: "cityCode") as? String ?? ""
-        self.province = decoder.decodeObject(forKey: "province") as? String ?? ""
-        self.city = decoder.decodeObject(forKey: "city") as? String ?? ""
-        self.district = decoder.decodeObject(forKey: "district") as? String ?? ""
-        self.street = decoder.decodeObject(forKey: "street") as? String ?? ""
-        self.locationDescribe = decoder.decodeObject(forKey: "locationDescribe") as? String ?? ""
-    }
+    required init?(coder aDecoder: NSCoder) {
+        self.latitude = aDecoder.decodeObject(forKey: "latitude") as? String ?? ""
+        self.longitude = aDecoder.decodeObject(forKey: "longitude") as? String ?? ""
+        self.country = aDecoder.decodeObject(forKey: "country") as? String ?? ""
+        self.countryCode = aDecoder.decodeObject(forKey: "countryCode") as? String ?? ""
+        self.province = aDecoder.decodeObject(forKey: "province") as? String ?? ""
+        self.city = aDecoder.decodeObject(forKey: "city") as? String ?? ""
+        self.district = aDecoder.decodeObject(forKey: "district") as? String ?? ""
+        self.street = aDecoder.decodeObject(forKey: "street") as? String ?? ""
+        self.streetNumber = aDecoder.decodeObject(forKey: "streetNumber") as? String ?? ""
+        self.cityCode = aDecoder.decodeObject(forKey: "cityCode") as? String ?? ""
+        self.adCode = aDecoder.decodeObject(forKey: "adCode") as? String ?? ""
+        self.locationDescribe = aDecoder.decodeObject(forKey: "locationDescribe") as? String ?? ""
 
+    }
 
     /// 归档
     ///
@@ -68,20 +68,23 @@ class LocationModel: NSObject,NSCoding {
     func encode(with aCoder: NSCoder) {
         aCoder.encode(self.latitude, forKey:"latitude")
         aCoder.encode(self.longitude, forKey:"longitude")
-        aCoder.encode(self.cityCode, forKey:"cityCode")
+        aCoder.encode(self.country, forKey:"country")
+        aCoder.encode(self.countryCode, forKey:"countryCode")
         aCoder.encode(self.province, forKey:"province")
         aCoder.encode(self.city, forKey:"city")
         aCoder.encode(self.district, forKey:"district")
-        aCoder.encode(self.street, forKey:"street")
+        aCoder.encode(self.street, forKey:"locationDescribe")
+        aCoder.encode(self.streetNumber, forKey:"streetNumber")
+        aCoder.encode(self.cityCode, forKey:"cityCode")
+        aCoder.encode(self.adCode, forKey:"adCode")
         aCoder.encode(self.locationDescribe, forKey:"locationDescribe")
 
     }
 
-
     /// 存储定位信息
     ///
     /// - Parameter locationModel: 定位模型
-    class func setLocationModel(locationModel:LocationModel) -> Void {
+    func setLocationModel(locationModel:LocationModel) -> Void {
         //实例对象转换成Data
         let modelData = NSKeyedArchiver.archivedData(withRootObject: locationModel)
         //存储Data对象
@@ -92,21 +95,25 @@ class LocationModel: NSObject,NSCoding {
     /// 获取定位信息
     ///
     /// - Returns: 定位模型
-    class func getLocationModel() -> LocationModel? {
+    func getLocationModel() -> LocationModel? {
         //自定义对象读取
         let modelData = UserDefaults.standard.data(forKey: "LocationModel")
-        let locationModel : LocationModel?
+        var locationModel = LocationModel()
         if modelData != nil {
-            locationModel = NSKeyedUnarchiver.unarchiveObject(with: modelData!) as? LocationModel
-        }else {
-            locationModel = self.init(latitude: "36.20630464252636", longitude: "113.07274820385199", cityCode: "140411", province: "山西省", city: "长治市", district: "郊区", street: "西外环路", locationDescribe: "在暴马村新兴小区附近")
+            locationModel = NSKeyedUnarchiver.unarchiveObject(with: modelData!) as! LocationModel
         }
-        NXLLog(locationModel!.toString())
-         return locationModel
+        toString()
+        return locationModel
     }
 
-    func toString() -> String {
-        return (self.province+self.city+self.district+self.street+self.locationDescribe)
+    func toString() {
+        let str = self.country +
+            self.province +
+            self.city +
+            self.district +
+            self.street +
+            self.locationDescribe
+        NXLLog(str)
     }
 
 }

+ 0 - 3
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallNavigationBarView.swift

@@ -121,9 +121,6 @@ class ShoppingMallNavigationBarView: BaseView {
         addressLabel.lineBreakMode = .byTruncatingTail
         addressLabel.numberOfLines = 1
         addressLabel.text = "正在定位"
-        BaiduMapManager.shared().initLocation { (locationModel) in
-            addressLabel.text = locationModel.toString()
-        }
         return addressLabel
     }()