質問編集履歴
1
文章の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,59 +1,38 @@
|
|
1
|
+
UnityのLocationServicceを使用して以下のコード(不要な部分は省略)を使用してGPSの値をとっているのですが誤差がひどいです。
|
2
|
+
端末はAndroidで高精度モードです。
|
3
|
+
|
4
|
+
private double dlatitude,dlongitude,daltitude;
|
5
|
+
public double slatitude, slongitude, saltitude;
|
1
6
|
IEnumerator Start(){
|
2
|
-
// First, check if user has location service enabled
|
3
|
-
if (!Input.location.isEnabledByUser)
|
4
|
-
yield break;
|
5
7
|
|
6
|
-
// Start service before querying location
|
7
|
-
|
8
|
+
slatitude = Input.location.lastData.latitude;
|
9
|
+
slongitude = Input.location.lastData.longitude;
|
10
|
+
saltitude = Input.location.lastData.altitude;
|
11
|
+
slatitude = double.Parse(slatitude.ToString ("N6"));
|
12
|
+
slongitude = double.Parse(slongitude.ToString ("N6"));
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
|
12
|
-
yield return new WaitForSeconds (1);
|
13
|
-
maxWait--;
|
14
|
-
}
|
15
|
-
|
16
|
-
// Service didn't initialize in 20 seconds
|
17
|
-
if (maxWait < 1) {
|
18
|
-
print ("Timed out");
|
19
|
-
yield break;
|
20
|
-
}
|
21
|
-
|
22
|
-
// Connection has failed
|
23
|
-
if (Input.location.status == LocationServiceStatus.Failed) {
|
24
|
-
print ("Unable to determine device location");
|
25
|
-
yield break;
|
26
|
-
} else {
|
27
|
-
// Access granted and location value could be retrieved
|
28
|
-
print ("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
|
29
|
-
}
|
30
|
-
slatitude = Input.location.lastData.latitude;
|
31
|
-
slongitude = Input.location.lastData.longitude;
|
32
|
-
saltitude = Input.location.lastData.altitude;
|
33
|
-
slatitude = double.Parse(slatitude.ToString ("N6"));
|
34
|
-
slongitude = double.Parse(slongitude.ToString ("N6"));
|
35
|
-
// Stop service if there is no need to query location updates continuously
|
36
|
-
//Input.location.Stop ();
|
37
|
-
}
|
38
|
-
|
39
|
-
void Update()
|
40
|
-
{
|
14
|
+
}
|
15
|
+
void Update(){
|
41
16
|
dlatitude = Input.location.lastData.latitude;
|
42
17
|
dlongitude = Input.location.lastData.longitude;
|
43
18
|
daltitude = Input.location.lastData.altitude;
|
44
|
-
|
45
|
-
dlatitude =
|
19
|
+
dlatitude = double.Parse(dlatitude.ToString ("N6"));
|
46
20
|
dlongitude = double.Parse(dlongitude.ToString ("N6"));
|
47
21
|
|
48
|
-
|
22
|
+
text.text = "開始地点:" + slatitude + "," + slongitude
|
49
|
-
|
23
|
+
"現在地:" + dlatitude + "," + dlongitude;
|
24
|
+
|
25
|
+
}
|
50
26
|
|
51
|
-
|
27
|
+
Start()でアプリの開始位置の位置情報をとりslatitude,slongitudeへ格納しています。Updateでは現在の位置情報をとりdlatitude,dlongitudeへ格納しています。
|
52
|
-
CamPos.y = 0.0f;
|
53
|
-
CamPos.z = (float)detlat;
|
54
|
-
|
28
|
+
アプリを起動して静止しtextのslatitudeとdlatitude,slongitudeとdlonngitudeが一致するのを待ちます。
|
29
|
+
しかし、1mくらい動くとdlatitude,dlongitudeがslatitude,slongitudeから大きくずれてしまいます。数十メートルから数百メートルずれてしまいます。ずれは緯度経度の桁から判断しています。
|
55
30
|
|
31
|
+
端末の移動量を計算することが必須のアプリなので誤差がここまでひどいと役に立ちません。
|
32
|
+
|
56
|
-
|
33
|
+
Start()でとった位置情報がアプリ起動の場所から大きくずれていることは確認しました。アプリ起動時に得られる位置情報は誤差が大きいのでしょうか?
|
34
|
+
どうしても開始位置の位置情報を所得必要があります。
|
35
|
+
|
36
|
+
できるだけ正確に開始位置をとりたいのですが、Start関数だと正確に得ることは難しいのでしょうか?
|
57
|
-
|
37
|
+
Start()でslatitude,slongitude
|
58
|
-
|
59
|
-
|
38
|
+
Update()でdlatitude,dlongitudeを所得しています。
|