mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-11 05:45:56 +10:00
Coordinate safe version property
This commit is contained in:
@@ -157,8 +157,8 @@ class ImageCache {
|
||||
let fileName = message.localAttachmentName
|
||||
|
||||
// 再保证一次,防止旧消息导致错误
|
||||
let latitude: CLLocationDegrees = abs(coordinate.latitude) > 90 ? 0 : coordinate.latitude
|
||||
let longitude: CLLocationDegrees = abs(coordinate.longitude) > 180 ? 0 : coordinate.longitude
|
||||
let latitude: CLLocationDegrees = coordinate.safeLatitude
|
||||
let longitude: CLLocationDegrees = coordinate.safeLongitude
|
||||
|
||||
dispatch_async(self.cacheQueue) {
|
||||
|
||||
|
||||
+10
-1
@@ -195,7 +195,16 @@ class Coordinate: Object {
|
||||
dynamic var latitude: Double = 0 // 合法范围 (-90, 90)
|
||||
dynamic var longitude: Double = 0 // 合法范围 (-180, 180)
|
||||
|
||||
func configureWithLatitude(latitude: Double, longitude: Double) {
|
||||
// NOTICE: always use safe version property
|
||||
|
||||
var safeLatitude: Double {
|
||||
return abs(latitude) > 90 ? 0 : latitude
|
||||
}
|
||||
var safeLongitude: Double {
|
||||
return abs(longitude) > 180 ? 0 : longitude
|
||||
}
|
||||
|
||||
func safeConfigureWithLatitude(latitude: Double, longitude: Double) {
|
||||
self.latitude = abs(latitude) > 90 ? 0 : latitude
|
||||
self.longitude = abs(longitude) > 180 ? 0 : longitude
|
||||
}
|
||||
|
||||
@@ -1393,7 +1393,7 @@ func createAndSendMessageWithMediaType(mediaType: MessageMediaType, inFilePath f
|
||||
latitude = messageInfo["latitude"] as? Double {
|
||||
|
||||
let coordinate = Coordinate()
|
||||
coordinate.configureWithLatitude(latitude, longitude: longitude)
|
||||
coordinate.safeConfigureWithLatitude(latitude, longitude: longitude)
|
||||
|
||||
message.coordinate = coordinate
|
||||
}
|
||||
|
||||
@@ -877,7 +877,7 @@ func recordMessageWithMessageID(messageID: String, detailInfo messageInfo: JSOND
|
||||
latitude = messageInfo["latitude"] as? Double {
|
||||
|
||||
let coordinate = Coordinate()
|
||||
coordinate.configureWithLatitude(latitude, longitude: longitude)
|
||||
coordinate.safeConfigureWithLatitude(latitude, longitude: longitude)
|
||||
|
||||
message.coordinate = coordinate
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user