3

ユーザーが特定のエリア内にいるかどうかをアプリケーションに認識させたい。私はジオフェンスについて学んでいますが、デバイスがエリアに出入りしているかどうかを常にチェックするのではなく、その具体的な瞬間にデバイスがオンになっているかどうかを知りたいだけです。さらに、ジオフェンスの精度は(どうやら)低く、セルラータワーの精度以上のものが必要だと読んだことがあります。
したがって、「標準」の種類の場所を使用してこれを行うという考えですが、新しい現在の場所を指定して、それが(円形、長方形、多角形?)領域内にあるかどうかを確認する方法がわかりません。
純粋数学を使用して、高度が2つのパラメーターの間にあるかどうかを確認し、経度を確認する必要があるかもしれません。もっと簡単な方法はありますか?

ありがとう!

4

3 に答える 3

1

CLLocationsのdistanceFromLocationを使用します

http://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html

于 2012-05-16T17:06:48.643 に答える
1

これが、ジョルダン曲線定理のSwiftコードです。CLLocationCoordinate2D正方形や多角形など、実際に何でも作成できる配列を提供するだけです。

私がこれを翻訳したより詳細な回答: 2Dポイントがポリゴン内にあるかどうかをどのように判断できますか?

元のウェブサイト:PNPOLY-ポリゴンテストのポイントインクルージョンW.ランドルフフランクリン(WRF)

extension CLLocationCoordinate2D {

    func liesInsideRegion(region:[CLLocationCoordinate2D]) -> Bool {

        var liesInside = false
        var i = 0
        var j = region.count-1

        while i < region.count {

            guard let iCoordinate = region[safe:i] else {break}
            guard let jCoordinate = region[safe:j] else {break}

            if (iCoordinate.latitude > self.latitude) != (jCoordinate.latitude > self.latitude) {
                if self.longitude < (iCoordinate.longitude - jCoordinate.longitude) * (self.latitude - iCoordinate.latitude) / (jCoordinate.latitude-iCoordinate.latitude) + iCoordinate.longitude {
                    liesInside = !liesInside
                    }
            }

            i += 1
            j = i+1
        }

        return liesInside
    }

}

編集

安全な配列アイテム

extension MutableCollection {
    subscript (safe index: Index) -> Iterator.Element? {
        get {
            guard startIndex <= index && index < endIndex else { return nil }
            return self[index]
        }
        set(newValue) {
            guard startIndex <= index && index < endIndex else { print("Index out of range."); return }
            guard let newValue = newValue else { print("Cannot remove out of bounds items"); return }
            self[index] = newValue
        }
    }
}
于 2016-10-28T09:19:34.853 に答える
0

Google Map SDKを使用していて、ポイントがポリゴン内にあるかどうかを確認したい場合は、を使用してみてくださいGMSGeometryContainsLocation。@Magooの答えは、ポリゴンが凸でない場合にうまく機能します。しかし、それが凹型である場合、@Magooのメソッドは役に立ちませんでした。

if GMSGeometryContainsLocation(point, polygon, true) {
    print("Inside this polygon.")
} else {
    print("outside this polygon")
}

参照は次のとおりです:https ://developers.google.com/maps/documentation/ios-sdk/reference/group___geometry_utils#gaba958d3776d49213404af249419d0ffd

于 2020-03-18T00:30:07.897 に答える