Skip to content

Instantly share code, notes, and snippets.

@daniele-quero
Last active June 17, 2022 08:58
Show Gist options
  • Save daniele-quero/38537bd7207942cd8170f9cadab6af55 to your computer and use it in GitHub Desktop.
Save daniele-quero/38537bd7207942cd8170f9cadab6af55 to your computer and use it in GitHub Desktop.
public class MapsAPIHandler
{
public string googleStaticMapsAPIkey = "my_api_key";
public string staticMapUrl = "https://maps.googleapis.com/maps/api/staticmap";
public MapsRequest mapsRequest = new MapsRequest();
//builds the API request object
public void GetStaticMapRequest(int width, int height) {...}
public IEnumerator DownloadMap(RawImage image, int width, int height)
{
GetStaticMapRequest(width, height);
UnityWebRequest web = UnityWebRequestTexture.GetTexture(mapsRequest.Url);
yield return web.SendWebRequest();
if (web.result == UnityWebRequest.Result.ConnectionError)
Debug.LogError(web.error);
else
image.texture = DownloadHandlerTexture.GetContent(web);
web.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment