Coordinate safe version property

This commit is contained in:
nixzhu
2015-08-10 15:35:51 +08:00
parent bec63ded77
commit 8c8fe6aeb8
4 changed files with 14 additions and 5 deletions
+2 -2
View File
@@ -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
View File
@@ -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
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
}