質問編集履歴
1
ソースコードの入力し忘れのため補足いたしました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Monacaを用いて位置情報を表示し、位置情報のポイントを保存させる
|
test
CHANGED
@@ -18,6 +18,10 @@
|
|
18
18
|
|
19
19
|
エラーメッセージ
|
20
20
|
|
21
|
+
save_geopoint
|
22
|
+
|
23
|
+
現在位置を取得できませんでした。
|
24
|
+
|
21
25
|
{"code":3,"message":"Position retrieval timed out."}
|
22
26
|
|
23
27
|
|
@@ -26,11 +30,157 @@
|
|
26
30
|
|
27
31
|
|
28
32
|
|
29
|
-
|
33
|
+
Javascript
|
30
34
|
|
31
35
|
ソースコード
|
32
36
|
|
37
|
+
|
38
|
+
|
39
|
+
/OSMの描画時に位置情報取得に成功した場合のコールバック
|
40
|
+
|
41
|
+
var onGeoSuccess = function(position){
|
42
|
+
|
43
|
+
console.debug("onGeoSuccess()");
|
44
|
+
|
45
|
+
currentUser = new CurrentPoint();
|
46
|
+
|
47
|
+
currentUser.geopoint = position.coords; //位置情報を保存する
|
48
|
+
|
49
|
+
writemap(currentUser.geopoint.longitude,currentUser.geopoint.latitude);
|
50
|
+
|
51
|
+
};
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
//位置情報取得に失敗した場合のコールバック
|
56
|
+
|
57
|
+
var onGeoError = function(error){
|
58
|
+
|
59
|
+
console.log("現在位置を取得できませんでした");
|
60
|
+
|
61
|
+
console.log(error);
|
62
|
+
|
63
|
+
return error && error.code !== 3 && error.message;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
};
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//位置情報取得時に設定するオプション
|
76
|
+
|
77
|
+
var geoOption = {
|
78
|
+
|
79
|
+
timeout: 6000
|
80
|
+
|
81
|
+
};
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
function onMouseClick(evt) {
|
86
|
+
|
87
|
+
console.debug("onMouseClick()");
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
//現在地を保持するクラスを作成
|
94
|
+
|
95
|
+
function CurrentPoint(){
|
96
|
+
|
97
|
+
geopoint=null; //端末の位置情報を保持する
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
//現在地をポイントとして登録する
|
104
|
+
|
105
|
+
function save_geopoint(){
|
106
|
+
|
107
|
+
navigator.geolocation.getCurrentPosition(onSaveSuccess, onGeoError, geoOption);
|
108
|
+
|
109
|
+
console.log("save_geopoint");
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
//ポイントの登録時に位置情報取得に成功した場合のコールバック
|
116
|
+
|
117
|
+
var onSaveSuccess = function(location){
|
118
|
+
|
119
|
+
console.debug("onSaveSuccess");
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
navigator.notification.prompt(
|
124
|
+
|
125
|
+
' ', // メッセージ
|
126
|
+
|
127
|
+
onPrompt, // 呼び出すコールバック
|
128
|
+
|
129
|
+
'ポンイントの登録', // タイトル
|
130
|
+
|
131
|
+
['登録','やめる'], // ボタンのラベル名
|
132
|
+
|
133
|
+
'ポイント名' // デフォルトのテキスト
|
134
|
+
|
135
|
+
);
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
function onPrompt(results) {
|
140
|
+
|
141
|
+
current.geopoint = location.coords;
|
142
|
+
|
143
|
+
var geoPoint = new ncmb.GeoPoint(location.coords.latitude, location.coords.longitude);
|
144
|
+
|
145
|
+
console.log(location.coords.latitude + ":" + location.coords.longitude);
|
146
|
+
|
147
|
+
var Places = ncmb.DataStore("PlacePoints");
|
148
|
+
|
149
|
+
var point = new Places();
|
150
|
+
|
151
|
+
point.set("name",results.input1);
|
152
|
+
|
153
|
+
point.set("geo", geoPoint);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
point.save()
|
158
|
+
|
159
|
+
.then(function(){
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
var marker = L.marker([location.coords.latitude, location.coords.longitude])
|
164
|
+
|
165
|
+
.bindPopup("<h1>" + results.input1 + "</h1>")
|
166
|
+
|
167
|
+
.addTo(map);
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
})
|
174
|
+
|
175
|
+
.catch(function(err){// エラー処理
|
176
|
+
|
33
|
-
|
177
|
+
});
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
};
|
34
184
|
|
35
185
|
|
36
186
|
|
@@ -38,12 +188,16 @@
|
|
38
188
|
|
39
189
|
|
40
190
|
|
191
|
+
エラーメッセージで検索したところ位置情報のタイムアウトが考えられたので
|
192
|
+
|
193
|
+
https://docs.monaca.io/ja/reference/cordova_9.0/geolocation/
|
194
|
+
|
41
|
-
|
195
|
+
上記のサイトを参考にし、config.xmlファイルに
|
196
|
+
|
42
|
-
|
197
|
+
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
|
198
|
+
|
43
|
-
|
199
|
+
<string>need location access to find things nearby</string>
|
44
|
-
|
200
|
+
|
45
|
-
|
201
|
+
</edit-config>
|
46
|
-
|
47
|
-
|
48
|
-
|
202
|
+
|
49
|
-
こ
|
203
|
+
上記のコードを入力し実行したところエラーはなくならずに詰まってしまいました。もしよろしければご教授のほどよろしくお願いいたします。
|