を使用しています。
func payTime() {
if driverLocation?.latitude == userLocation?.latitude && driverLocation?.longitude == userLocation?.longitude {
// Overlapping
}
}
ただし、これはまったく同じ場所にある場合にのみ有効です。あるいは、次のようなものを使用することができます。
func payTime() {
if let driverLocation = driverLocation, let userLocation = userLocation{
let driverLoc = CLLocation(latitude: driverLocation.latitude, longitude: driverLocation.longitude)
let userLoc = CLLocation(latitude: userLocation.latitude, longitude: userLocation.longitude)
if driverLoc.distance(from: userLoc) < 10{
// Overlapping
}
}
}
これは、2つのポイントをCLLocationに変換してから、どれくらい離れているかをメートルでチェックします。あなたは望みの結果を得るために閾値で遊ぶことができます。
編集1:ここでは
は、それが簡単に簡単に場所を比較できるようにする拡張機能です。
extension CLLocationCoordinate2D{
func isWithin(meters: Double, of: CLLocationCoordinate2D) -> Bool{
let currentLoc = CLLocation(latitude: self.latitude, longitude: self.longitude)
let comparingLoc = CLLocation(latitude: of.latitude, longitude: of.longitude)
return currentLoc.distance(from: comparingLoc) < meters
}
}
func payTime() {
if let driverLocation = driverLocation, let userLocation = userLocation{
if driverLocation.isWithin(meters: 10, of: userLocation){
// Overlapping
}
}
}
ここでエラーは何ですか? – NRitH