地理的な方向、すなわち東北北、東南東、南、南西、西、西北を得るために磁気見出し値を計算する方法は?磁気見出しを使用して地理的な方向を取得します。
磁気見出しは、継続的に更新された磁気見出しに基づいて、地理的方向を示すために必要な程度の値とその値を返します。
どうすればできますか?
地理的な方向、すなわち東北北、東南東、南、南西、西、西北を得るために磁気見出し値を計算する方法は?磁気見出しを使用して地理的な方向を取得します。
磁気見出しは、継続的に更新された磁気見出しに基づいて、地理的方向を示すために必要な程度の値とその値を返します。
どうすればできますか?
以下は、私が地理的な方向を更新し続けているコードです。
CGFloat currentHeading = newHeading.magneticHeading;
NSString *strDirection = [[NSString alloc] init];
if(gradToRotate >23 && gradToRotate <= 67){
strDirection = @"NE";
} else if(gradToRotate >68 && gradToRotate <= 112){
strDirection = @"E";
} else if(gradToRotate >113 && gradToRotate <= 167){
strDirection = @"SE";
} else if(gradToRotate >168 && gradToRotate <= 202){
strDirection = @"S";
} else if(gradToRotate >203 && gradToRotate <= 247){
strDirection = @"SW";
} else if(gradToRotate >248 && gradToRotate <= 293){
strDirection = @"W";
} else if(gradToRotate >294 && gradToRotate <= 337){
strDirection = @"NW";
} else if(gradToRotate >=338 || gradToRotate <= 22){
strDirection = @"N";
}
私の最後にはうまくいきます。修理が必要な場合は、修士課程にご連絡ください。
正確な地理的な方向を特定するための標準的な度合いが見つからないので、この計算をコンパスと比較して設定します。 –
ちょうど素晴らしい(2年後でも人々に役立つ):-) ..どのようにあなたは度のためのこれらの値を得ましたか?どんな情報源? – thandasoru
ありがとうございます。ソースなし、純粋に自己実装のロジック。 –
GithubのMatt Neuburgが提供するこのサンプルを試してみてください。 https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch22p775heading/ch35p1035heading/ViewController.swift
func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
var h = newHeading.magneticHeading
let h2 = newHeading.trueHeading // will be -1 if we have no location info
print("\(h) \(h2) ")
if h2 >= 0 {
h = h2
}
let cards = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
var dir = "N"
for (ix, card) in cards.enumerate() {
if h < 45.0/2.0 + 45.0*Double(ix) {
dir = card
break
}
}
print(dir)
}
これは完璧です!
ありがとうございました。 – fozoglu
CLLocationDirection heading = ((newHeading.trueHeading > 0) ?
newHeading.trueHeading : newHeading.magneticHeading);
NSString *geoDirectionString = [[NSString alloc] init];
if(heading >22.5 && heading <= 67.5){
geoDirectionString = @"North East";
} else if(heading >67.5 && heading <= 112.5){
geoDirectionString = @"East";
} else if(heading >112.5 && heading <= 157.5){
geoDirectionString = @"South East";
} else if(heading >157.5 && heading <= 202.5){
geoDirectionString = @"South";
} else if(heading >202.5 && heading <= 247.5){
geoDirectionString = @"South West";
} else if(heading >248 && heading <= 293){
geoDirectionString = @"West";
} else if(heading >247.5 && heading <= 337.5){
geoDirectionString = @"North West";
} else if(heading >=337.5 || heading <= 22.5){
geoDirectionString = @"North";
}
すでにmapKitライブラリにその機能が追加されていると思います。あなたはそれをチェックアウトする必要があります。 – Radu
私はそのような機能を見つけることはありません。もし見つかった場合は、私に知らせてください。 –
私は自分で解決策を見つけました。私は実装されたロジックをテストし、Compassと同じものを比較しています。 –