|
@@ -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)
|
|
|
}
|
|
|
|
|
|
}
|