質問編集履歴

1

文章の修正

2017/12/04 13:10

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,82 +1,32 @@
1
- IEnumerator Start(){
1
+ UnityのLocationServicceを使用して以下のコード(不要な部分は省略)を使用してGPSの値をとっているのですが誤差がひどいです。
2
2
 
3
- // First, check if user has location service enabled
4
-
5
- if (!Input.location.isEnabledByUser)
3
+ 端末はAndroidで高精度モードです。
6
-
7
- yield break;
8
4
 
9
5
 
10
6
 
11
- // Start service before querying location
7
+ private double dlatitude,dlongitude,daltitude;
12
8
 
9
+ public double slatitude, slongitude, saltitude;
10
+
13
- Input.location.Start ();
11
+ IEnumerator Start(){
14
12
 
15
13
 
16
14
 
17
- // Wait until service initializes
15
+ slatitude = Input.location.lastData.latitude;
18
16
 
19
- int maxWait = 20;
17
+ slongitude = Input.location.lastData.longitude;
20
18
 
21
- while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
19
+ saltitude = Input.location.lastData.altitude;
22
20
 
23
- yield return new WaitForSeconds (1);
21
+ slatitude = double.Parse(slatitude.ToString ("N6"));
24
22
 
25
- maxWait--;
23
+ slongitude = double.Parse(slongitude.ToString ("N6"));
26
-
27
- }
28
24
 
29
25
 
30
26
 
31
- // Service didn't initialize in 20 seconds
27
+ }
32
28
 
33
- if (maxWait < 1) {
34
-
35
- print ("Timed out");
36
-
37
- yield break;
38
-
39
- }
40
-
41
-
42
-
43
- // Connection has failed
44
-
45
- if (Input.location.status == LocationServiceStatus.Failed) {
46
-
47
- print ("Unable to determine device location");
48
-
49
- yield break;
50
-
51
- } else {
52
-
53
- // Access granted and location value could be retrieved
54
-
55
- print ("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
56
-
57
- }
58
-
59
- slatitude = Input.location.lastData.latitude;
60
-
61
- slongitude = Input.location.lastData.longitude;
62
-
63
- saltitude = Input.location.lastData.altitude;
64
-
65
- slatitude = double.Parse(slatitude.ToString ("N6"));
66
-
67
- slongitude = double.Parse(slongitude.ToString ("N6"));
68
-
69
- // Stop service if there is no need to query location updates continuously
70
-
71
- //Input.location.Stop ();
72
-
73
- }
74
-
75
-
76
-
77
- void Update()
78
-
79
- {
29
+ void Update(){
80
30
 
81
31
  dlatitude = Input.location.lastData.latitude;
82
32
 
@@ -84,34 +34,42 @@
84
34
 
85
35
  daltitude = Input.location.lastData.altitude;
86
36
 
87
-
88
-
89
- dlatitude = double.Parse(dlatitude.ToString ("N6"));
37
+ dlatitude = double.Parse(dlatitude.ToString ("N6"));
90
38
 
91
39
  dlongitude = double.Parse(dlongitude.ToString ("N6"));
92
40
 
93
41
 
94
42
 
95
- detlat = CalcDetLat (slatitude, dlatitude);
96
-
97
- detlon = CalcDetLon (slongitude, dlongitude);
98
-
99
-
100
-
101
- CamPos.x = (float)detlon;
102
-
103
- CamPos.y = 0.0f;
104
-
105
- CamPos.z = (float)detlat;
106
-
107
- ARCamera.transform.position = CamPos;
108
-
109
-
110
-
111
- text.text = "開始地点:" + slatitude + "," + slongitude + "\n" +
43
+ text.text = "開始地点:" + slatitude + "," + slongitude
112
44
 
113
45
  "現在地:" + dlatitude + "," + dlongitude;
114
46
 
115
47
 
116
48
 
117
- }
49
+ }
50
+
51
+
52
+
53
+ Start()でアプリの開始位置の位置情報をとりslatitude,slongitudeへ格納しています。Updateでは現在の位置情報をとりdlatitude,dlongitudeへ格納しています。
54
+
55
+ アプリを起動して静止しtextのslatitudeとdlatitude,slongitudeとdlonngitudeが一致するのを待ちます。
56
+
57
+ しかし、1mくらい動くとdlatitude,dlongitudeがslatitude,slongitudeから大きくずれてしまいます。数十メートルから数百メートルずれてしまいます。ずれは緯度経度の桁から判断しています。
58
+
59
+
60
+
61
+ 端末の移動量を計算することが必須のアプリなので誤差がここまでひどいと役に立ちません。
62
+
63
+
64
+
65
+ Start()でとった位置情報がアプリ起動の場所から大きくずれていることは確認しました。アプリ起動時に得られる位置情報は誤差が大きいのでしょうか?
66
+
67
+ どうしても開始位置の位置情報を所得必要があります。
68
+
69
+
70
+
71
+ できるだけ正確に開始位置をとりたいのですが、Start関数だと正確に得ることは難しいのでしょうか?
72
+
73
+ Start()でslatitude,slongitude
74
+
75
+ Update()でdlatitude,dlongitudeを所得しています。