How to use Google Maps in Unity url error

Asked 2 years ago, Updated 2 years ago, 94 views

Unity wants to use Google Maps.

There are a few sets out, but I'm going to do it myself.

using UnityEngine;
using System.Collections;

public class GoogleMapAPI : MonoBehaviour
{
    private bool loadingMap;

    string url = "";

    public float lat =0.0f;

    public float lon = 0.0f;
    LocationInfo li;


    public int zoom = 14;

    public int mapWidth = 640;
    public int mapHeigh = 640;

    public enum mapType { roadmap, satellite, hybrid, terrain };

    public mapType mapSelected;

    public int scale;
    IEnumerator GetGoogleMap()
    {
        url = "https://maps.googleapis.com/maps/api/staticmap?center=" + lat + "," + lon +
                    "&zoom=" + zoom + "&size=" + mapWidth + "x" + mapHeigh + "&scale=" + scale
                    + + "&maptype=" + mapSelected +
                    "&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7.7187,91871871828,7187,7187,7187,7187,98.98.98.98.98.98.98.98.98.98.98.98.98.98.98.98.74.0174.0174.01.74.";
        loadingMap = true;
        WWW www = new WWW(url);
        yield return www;
        loadingMap = false;

        gameObject.GetComponent<Renderer>().material.mainTexture = www.texture;
    }
    void Start()
    {

        StartCoroutine(GetGoogleMap());
    }
}

I wrote it in the same code as above, but the first method is

You are trying to load data from a www stream which had the following error when downloading. 403 Forbidden There was an error.

The url information seems to be invalid, but I can't find an address to retrieve the map information.

If there are people who have experienced it, please respond.

google unity c#

2022-09-22 08:15

1 Answers

I put the code you uploaded into the 3D cube and executed it, and it was executed as below.

However, url is Google Maps API Static Maps API for the web You used the demo url shown in .

https://maps.googleapis.com/maps/api/staticmap?center=Australia&size=640x400&style=element:labels|visibility:off&style=element:geometry.stroke|visibility:off&style=feature:landscape|element:geometry|saturation:-100&style=feature:water|saturation:-100|invert_lightness:true&key=YOUR_API_KEY

It seems that the url itself is wrong to send a request. First, type the url in your browser and try using it when it loads well.


2022-09-22 08:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.