質問編集履歴
1
実行しているコードを追記しました。(参考本原文です。)
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,6 +11,120 @@
|
|
11
11
|
この章最後の部分、「Google Maps Static APIを利用した地図表示」を行っていますが
|
12
12
|
|
13
13
|
アプリ画面にグーグルマップの表示を行うことができません。
|
14
|
+
|
15
|
+
コードは以下のものです。
|
16
|
+
|
17
|
+
```C#
|
18
|
+
|
19
|
+
using System.Collections;
|
20
|
+
|
21
|
+
using UnityEngine;
|
22
|
+
|
23
|
+
using UnityEngine.Networking;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
public class StaticMapController : MonoBehaviour
|
28
|
+
|
29
|
+
{
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
//Google Maps Static API URL
|
34
|
+
|
35
|
+
// ${APIKey}を作成したapiキーに書き換えてください。
|
36
|
+
|
37
|
+
private const string STATIC_MAP_URL = "https://maps.googleapis.com/maps/api/staticmap?key=${APIKey}&zoom=15&size=640x640&scale=2&maptype=terrain&style=element:labels|visibility:off";
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
private int frame = 0;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
// Start is called before the first frame update
|
46
|
+
|
47
|
+
void Start()
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
// 非同期処理
|
52
|
+
|
53
|
+
StartCoroutine(getStaticMap());
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
// Update is called once per frame
|
60
|
+
|
61
|
+
void Update()
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
// 5秒に一度の実行
|
66
|
+
|
67
|
+
if (frame >= 300)
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
StartCoroutine(getStaticMap());
|
72
|
+
|
73
|
+
frame = 0;
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
frame++;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
IEnumerator getStaticMap()
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
var query = "";
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// centerで取得するミニマップの中央座標を設定
|
92
|
+
|
93
|
+
query += "¢er=" + UnityWebRequest.UnEscapeURL(string.Format("{0},{1}", Input.location.lastData.latitude, Input.location.lastData.longitude));
|
94
|
+
|
95
|
+
// markersで渡した座標(=現在位置)にマーカーを立てる
|
96
|
+
|
97
|
+
query += "&markers=" + UnityWebRequest.UnEscapeURL(string.Format("{0},{1}", Input.location.lastData.latitude, Input.location.lastData.longitude));
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
// リクエストの定義
|
102
|
+
|
103
|
+
var req = UnityWebRequestTexture.GetTexture(STATIC_MAP_URL + query);
|
104
|
+
|
105
|
+
// リクエスト実行
|
106
|
+
|
107
|
+
yield return req.SendWebRequest();
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if (req.error == null)
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
// すでに表示しているマップを更新
|
116
|
+
|
117
|
+
Destroy(GetComponent<Renderer>().material.mainTexture);
|
118
|
+
|
119
|
+
GetComponent<Renderer>().material.mainTexture = ((DownloadHandlerTexture)req.downloadHandler).texture;
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
```
|
14
128
|
|
15
129
|
|
16
130
|
|