teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

質問内容の復元

2017/01/13 04:18

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,83 @@
1
1
  ###前提・実現したいこと
2
2
  位置情報を追跡して、マップに移動経路を描画したいと考えています。
3
-
3
+ マップの表示、ポインタの設置、位置情報の追跡(geolocation:watchPosition)を行うことはできましたが、線の描画がうまくいきません。polylineを使用する予定ですが、watchpositionで取得した位置情報latlngをどのように格納して描画していけばいいのかわかりません。アドバイスや、実例をお願いしたいです。
4
4
  ###現在のプログラム
5
-
6
5
  ```
7
- エラーメッセージ
6
+ エラーメッセージ
7
+ // グローバル変数
8
+ var syncerWatchPosition = {
9
+ count: 0 ,
10
+ lastTime: 0 ,
11
+ map: null ,
12
+ marker: null ,
13
+ } ;
14
+ // 成功した時の関数
15
+ function successFunc( position )
16
+ {
17
+ // データの更新
18
+ ++syncerWatchPosition.count ; // 処理回数
19
+ // HTMLに書き出し
20
+ document.getElementById( 'result' ).innerHTML = '<dt>緯度</dt><dd>' + position.coords.latitude + '</dd><dt>経度</dt><dd>' + position.coords.longitude + '</dd><dt>高度</dt><dd>' + position.coords.altitude + '</dd><dt>速度</dt><dd>' + position.coords.speed + '</dd><dt>実行回数</dt><dd>' + syncerWatchPosition.count + '回</dd>' ;
21
+ // 位置情報
22
+ var latlng = new google.maps.LatLng( position.coords.latitude , position.coords.longitude ) ;
23
+ // Google Mapsに書き出し
24
+ //if( syncerWatchPosition.map == null )
25
+ //{
26
+ // 地図の新規出力
27
+ syncerWatchPosition.map = new google.maps.Map( document.getElementById( 'map-canvas' ) , {
28
+ zoom: 17 , // ズーム値
29
+ center: latlng , // 中心座標 [latlng]
30
+ } ) ;
31
+ // マーカーの新規出力
32
+ syncerWatchPosition.marker = new google.maps.Marker( {
33
+ map: syncerWatchPosition.map ,
34
+ position: latlng ,
35
+ } ) ;
36
+ map.drawRoute({
37
+ origin: [-12.044012922866312, -77.02470665341184],
38
+ destination: latlng,
39
+ travelMode: 'walking',
40
+ strokeColor: '#131540',
41
+ strokeOpacity: 0.6,
42
+ strokeWeight: 6
43
+ });
44
+ //}
45
+
46
+ }
47
+ // 失敗した時の関数
48
+ function errorFunc( error )
49
+ {
50
+ // エラーコードのメッセージを定義
51
+ var errorMessage = {
52
+ 0: "原因不明のエラーが発生しました…。" ,
53
+ 1: "位置情報の取得が許可されませんでした…。" ,
54
+ 2: "電波状況などで位置情報が取得できませんでした…。" ,
55
+ 3: "位置情報の取得に時間がかかり過ぎてタイムアウトしました…。" ,
56
+ } ;
57
+ // エラーコードに合わせたエラー内容を表示
58
+ alert( errorMessage[error.code] ) ;
59
+ }
60
+ // オプション・オブジェクト
61
+ var optionObj = {
62
+ "enableHighAccuracy": false ,
63
+ //"timeout": 1000000 ,
64
+ //"maximumAge": 0 ,
65
+ } ;
66
+ function Init(){
67
+ // 現在位置を取得する
68
+ navigator.geolocation.watchPosition( successFunc , errorFunc , optionObj ) ;
69
+ }
70
+ ```
71
+ ###参考ソースコード
72
+ LatLngを2つ、3つ、、、と記録していくことは可能でしょうか。
73
+ 最後に終了ボタンを押すことで記録した位置情報をすべて描画したいとも考えています。
74
+ ```
75
+ polylineOption = {
76
+ position: latlng , // 位置座標 [LatLngクラスで指定]
77
+ map: map ,
78
+ path: [
79
+ new google.maps.LatLng( 35.710382 , 139.797466 ) ,
80
+ new google.maps.LatLng( 35.710162 , 139.827963 ) ,
81
+ ] ,
82
+ } ;
83
+ ```

1

質問の変更

2017/01/13 04:18

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,97 +1,7 @@
1
1
  ###前提・実現したいこと
2
2
  位置情報を追跡して、マップに移動経路を描画したいと考えています。
3
- マップの表示、ポインタの設置、位置情報の追跡(geolocation:watchPosition)を行うことはできましたが、線の描画がうまくいきません。polylineを使用する予定ですが、watchpositionで取得した位置情報latlngをどのように格納して描画していけばいいのかわかりません。アドバイスや、実例をお願いしたいです。
3
+
4
4
  ###現在のプログラム
5
5
 
6
6
  ```
7
- エラーメッセージ
8
- // グローバル変数
9
-
10
- var syncerWatchPosition = {
11
- count: 0 ,
12
- lastTime: 0 ,
13
- map: null ,
14
- marker: null ,
15
- } ;
16
-
17
- // 成功した時の関数
18
- function successFunc( position )
19
- {
20
- // データの更新
21
- ++syncerWatchPosition.count ; // 処理回数
22
-
23
- // HTMLに書き出し
24
- document.getElementById( 'result' ).innerHTML = '<dt>緯度</dt><dd>' + position.coords.latitude + '</dd><dt>経度</dt><dd>' + position.coords.longitude + '</dd><dt>高度</dt><dd>' + position.coords.altitude + '</dd><dt>速度</dt><dd>' + position.coords.speed + '</dd><dt>実行回数</dt><dd>' + syncerWatchPosition.count + '回</dd>' ;
25
-
26
- // 位置情報
27
- var latlng = new google.maps.LatLng( position.coords.latitude , position.coords.longitude ) ;
28
-
29
- // Google Mapsに書き出し
30
- //if( syncerWatchPosition.map == null )
31
- //{
32
- // 地図の新規出力
33
- syncerWatchPosition.map = new google.maps.Map( document.getElementById( 'map-canvas' ) , {
34
- zoom: 17 , // ズーム値
35
- center: latlng , // 中心座標 [latlng]
36
- } ) ;
37
-
38
- // マーカーの新規出力
39
- syncerWatchPosition.marker = new google.maps.Marker( {
40
- map: syncerWatchPosition.map ,
41
- position: latlng ,
42
- } ) ;
43
-
44
- map.drawRoute({
45
- origin: [-12.044012922866312, -77.02470665341184],
46
- destination: latlng,
47
- travelMode: 'walking',
48
- strokeColor: '#131540',
49
- strokeOpacity: 0.6,
50
- strokeWeight: 6
51
- });
52
- //}
53
-
54
- }
55
-
56
- // 失敗した時の関数
57
- function errorFunc( error )
58
- {
59
- // エラーコードのメッセージを定義
60
- var errorMessage = {
61
- 0: "原因不明のエラーが発生しました…。" ,
62
- 1: "位置情報の取得が許可されませんでした…。" ,
63
- 2: "電波状況などで位置情報が取得できませんでした…。" ,
64
- 3: "位置情報の取得に時間がかかり過ぎてタイムアウトしました…。" ,
65
- } ;
66
-
67
- // エラーコードに合わせたエラー内容を表示
68
- alert( errorMessage[error.code] ) ;
69
- }
70
-
71
- // オプション・オブジェクト
72
- var optionObj = {
73
- "enableHighAccuracy": false ,
74
- //"timeout": 1000000 ,
75
- //"maximumAge": 0 ,
76
- } ;
77
-
78
- function Init(){
79
- // 現在位置を取得する
80
- navigator.geolocation.watchPosition( successFunc , errorFunc , optionObj ) ;
81
- }
82
-
83
- ```
84
- ###参考ソースコード
85
- LatLngを2つ、3つ、、、と記録していくことは可能でしょうか。
86
- 最後に終了ボタンを押すことで記録した位置情報をすべて描画したいとも考えています。
87
- ```
88
- polylineOption = {
89
- position: latlng , // 位置座標 [LatLngクラスで指定]
90
-
91
- map: map ,
92
- path: [
93
- new google.maps.LatLng( 35.710382 , 139.797466 ) ,
94
- new google.maps.LatLng( 35.710162 , 139.827963 ) ,
95
- ] ,
96
- } ;
97
- ```
7
+ エラーメッセージ