質問編集履歴
1
ソースコードの入力し忘れのため補足いたしました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Monacaを用いて位置情報を表示し、位置情報のポイントを保存させる
|
body
CHANGED
@@ -8,18 +8,95 @@
|
|
8
8
|
以下のようなエラー文が表示されます。他のサイトなどを検索
|
9
9
|
|
10
10
|
エラーメッセージ
|
11
|
+
save_geopoint
|
12
|
+
現在位置を取得できませんでした。
|
11
13
|
{"code":3,"message":"Position retrieval timed out."}
|
12
14
|
|
13
15
|
### 該当のソースコード
|
14
16
|
|
15
|
-
|
17
|
+
Javascript
|
16
18
|
ソースコード
|
17
|
-
```
|
18
19
|
|
19
|
-
|
20
|
+
/OSMの描画時に位置情報取得に成功した場合のコールバック
|
21
|
+
var onGeoSuccess = function(position){
|
22
|
+
console.debug("onGeoSuccess()");
|
23
|
+
currentUser = new CurrentPoint();
|
24
|
+
currentUser.geopoint = position.coords; //位置情報を保存する
|
25
|
+
writemap(currentUser.geopoint.longitude,currentUser.geopoint.latitude);
|
26
|
+
};
|
20
27
|
|
21
|
-
|
28
|
+
//位置情報取得に失敗した場合のコールバック
|
29
|
+
var onGeoError = function(error){
|
30
|
+
console.log("現在位置を取得できませんでした");
|
31
|
+
console.log(error);
|
32
|
+
return error && error.code !== 3 && error.message;
|
22
33
|
|
23
|
-
|
34
|
+
};
|
24
35
|
|
36
|
+
|
37
|
+
|
38
|
+
//位置情報取得時に設定するオプション
|
39
|
+
var geoOption = {
|
40
|
+
timeout: 6000
|
41
|
+
};
|
42
|
+
|
43
|
+
function onMouseClick(evt) {
|
44
|
+
console.debug("onMouseClick()");
|
45
|
+
}
|
46
|
+
|
47
|
+
//現在地を保持するクラスを作成
|
48
|
+
function CurrentPoint(){
|
49
|
+
geopoint=null; //端末の位置情報を保持する
|
50
|
+
}
|
51
|
+
|
25
|
-
|
52
|
+
//現在地をポイントとして登録する
|
53
|
+
function save_geopoint(){
|
54
|
+
navigator.geolocation.getCurrentPosition(onSaveSuccess, onGeoError, geoOption);
|
55
|
+
console.log("save_geopoint");
|
56
|
+
}
|
57
|
+
|
58
|
+
//ポイントの登録時に位置情報取得に成功した場合のコールバック
|
59
|
+
var onSaveSuccess = function(location){
|
60
|
+
console.debug("onSaveSuccess");
|
61
|
+
|
62
|
+
navigator.notification.prompt(
|
63
|
+
' ', // メッセージ
|
64
|
+
onPrompt, // 呼び出すコールバック
|
65
|
+
'ポンイントの登録', // タイトル
|
66
|
+
['登録','やめる'], // ボタンのラベル名
|
67
|
+
'ポイント名' // デフォルトのテキスト
|
68
|
+
);
|
69
|
+
|
70
|
+
function onPrompt(results) {
|
71
|
+
current.geopoint = location.coords;
|
72
|
+
var geoPoint = new ncmb.GeoPoint(location.coords.latitude, location.coords.longitude);
|
73
|
+
console.log(location.coords.latitude + ":" + location.coords.longitude);
|
74
|
+
var Places = ncmb.DataStore("PlacePoints");
|
75
|
+
var point = new Places();
|
76
|
+
point.set("name",results.input1);
|
77
|
+
point.set("geo", geoPoint);
|
78
|
+
|
79
|
+
point.save()
|
80
|
+
.then(function(){
|
81
|
+
|
82
|
+
var marker = L.marker([location.coords.latitude, location.coords.longitude])
|
83
|
+
.bindPopup("<h1>" + results.input1 + "</h1>")
|
84
|
+
.addTo(map);
|
85
|
+
|
86
|
+
|
87
|
+
})
|
88
|
+
.catch(function(err){// エラー処理
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
};
|
93
|
+
|
94
|
+
### 試したこと
|
95
|
+
|
96
|
+
エラーメッセージで検索したところ位置情報のタイムアウトが考えられたので
|
97
|
+
https://docs.monaca.io/ja/reference/cordova_9.0/geolocation/
|
98
|
+
上記のサイトを参考にし、config.xmlファイルに
|
99
|
+
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
|
100
|
+
<string>need location access to find things nearby</string>
|
101
|
+
</edit-config>
|
102
|
+
上記のコードを入力し実行したところエラーはなくならずに詰まってしまいました。もしよろしければご教授のほどよろしくお願いいたします。
|