I'm trying to embed Google Maps to my Unity Application by following this reference here https://developers.google.com/maps/documentation/embed/guide#overview . So far, I was able to successfully send the request, like there are no more errors but it does not load the map. It instead loads a big question mark like this below:
What is the reason for this? Here is the script attached to my Plane btw:
IEnumerator _Refresh ()
{
var url = "https://www.google.com/maps/embed/v1/place";
var qs = "";
if (!autoLocateCenter) {
qs += "key=AIzaSyDQ18r-LtVpuo__ms7yl4KW0k9VhMOadgQ";
qs += "&q=Cebu";
qs += "&maptype=" + mapType.ToString ().ToLower ();
qs += "&zoom=" + zoom.ToString ();
}
var usingSensor = false;
#if UNITY_IPHONE
usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;
#endif
//qs += "&sensor=" + (usingSensor ? "true" : "false");
foreach (var i in markers) {
qs += "&markers=" + string.Format ("size:{0}|color:{1}|label:{2}", i.size.ToString ().ToLower (), i.color, i.label);
foreach (var loc in i.locations) {
if (loc.address != "")
qs += "|" + WWW.UnEscapeURL (loc.address);
else
qs += "|" + WWW.UnEscapeURL (string.Format ("{0},{1}", loc.latitude, loc.longitude));
}
}
foreach (var i in paths) {
qs += "&path=" + string.Format ("weight:{0}|color:{1}", i.weight, i.color);
if(i.fill) qs += "|fillcolor:" + i.fillColor;
foreach (var loc in i.locations) {
if (loc.address != "")
qs += "|" + WWW.UnEscapeURL (loc.address);
else
qs += "|" + WWW.UnEscapeURL (string.Format ("{0},{1}", loc.latitude, loc.longitude));
}
}
var req = new WWW (url + "?" + qs);
yield return req;
GetComponent<Renderer> ().material.mainTexture = req.texture;
}
Google uses two different API for their map:
The link you provided is an Embed API. That can only be used on an html page like this:
<iframe src="//www.google.com/maps/embed/v1/place?q=Harrods,Brompton%20Rd,%20UK
&zoom=17
&key=YOUR_API_KEY">
</iframe>
The second method(Static API) returns an image when you make a request. This is what you should be using .
The url should be in this format:
https://maps.googleapis.com/maps/api/staticmap?....
instead of:
https://google.com/maps/embed/v1/place?....
So, your link should be something like this:
https://maps.googleapis.com/maps/api/staticmap?key=AIzaSyDQ18r-LtVpuo__ms7yl4KW0k9VhMOadgQ&q=Cebu+City&maptype=satellite&zoom=5&size=640x400.
Always try it in the browser before putting it in your code.
NOTE :
You have to enable/authorize Google Map static in the Google Developers Console. To see more supported parameters, see here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.