Example #1
0
    public IEnumerator Geolocate(string url, string qs)
    {
        WWW geocode = new WWW(url + qs + "&maxResults=1&key=" + key);

        yield return(geocode);

        GeocodedObject locationJson = JsonConvert.DeserializeObject <GeocodedObject>(geocode.text);

        if (locationJson.statusDescription == "OK")
        {
            centerCoord = locationJson.resourceSets[0].resources[0].point.coordinates;
        }
        else
        {
            Debug.Log("Something went wrong: no location retrieved from geolocation");
        }
    }
Example #2
0
    IEnumerator _Refresh()
    {
        string key  = "Aqb8ECpcSTeT8RxLKH-r7SiS5NI7JK2hVF5FZFKap30lls9Nc7fQWH_-OKjYButM";
        int    size = 512;

        GetComponent <Terrain> ().terrainData.size = new Vector3(25, 10, 25);
        GetComponent <Terrain> ().terrainData.heightmapResolution = size;

        List <double> centerCoord = new List <double>(2);
        string        url         = "http://dev.virtualearth.net/REST/v1/Locations?";
        string        qs          = "";

        qs += (centerLocation.locality != "") ? "locality=" + centerLocation.locality : "";
        qs += (centerLocation.adminDistrict != "") ? "&adminDistrict=" + centerLocation.adminDistrict : "";
        qs += (centerLocation.addressLine != "") ? "&addressLine=" + centerLocation.addressLine : "";
        qs += (centerLocation.ISOCountryRegion != "") ? "&countryRegion=" + centerLocation.ISOCountryRegion : "";

        if (qs != "")
        {
            WWW geocode = new WWW(url + qs + "&maxResults=1&key=" + key);
            yield return(geocode);

            GeocodedObject locationJson = JsonConvert.DeserializeObject <GeocodedObject>(geocode.text);
            if (locationJson.statusDescription == "OK")
            {
                centerCoord = locationJson.resourceSets[0].resources[0].point.coordinates;
            }
            else
            {
                Debug.Log("Something went wrong: no location retrieved from geolocation");
            }
        }
        else
        {
            if (centerLocation.latitude != 0 && centerLocation.longitude != 0)
            {
                centerCoord[0] = centerLocation.latitude;
                centerCoord[1] = centerLocation.longitude;
            }
            else
            {
                Debug.Log("Something went wrong: no valid coordinates found");
            }
        }
        //set up the request
        url = "http://dev.virtualearth.net/REST/v1/Imagery/Map/";
        qs  = "";
        qs += imSet + "/";
        qs += centerCoord[0] + "," + centerCoord[1] + "/";
        qs += centerLocation.zoom + "?";
        qs += "mapSize=" + size + "," + size;
        qs += "&key=" + key;

        string qs2 = qs;

        qs  += "&mapMetadata=0";        //for having the image
        qs2 += "&mapMetadata=1";        //for map metadata

        WWW reqImage = new WWW(url + qs);

        if (heights == true)
        {
            if (allowLoad && GameControl.control.LoadCurrent() &&
                GameControl.control.currentCenter[0] == centerCoord[0] &&
                GameControl.control.currentCenter[1] == centerCoord[1] &&
                GameControl.control.currentZoom == centerLocation.zoom)
            {
                Debug.Log("heightmap loaded");
                //GetComponent<Terrain> ().terrainData.SetHeights(0,0, GameControl.control.currentHeightmap);
                ApplyBingHeightmapToChunks(GameControl.control.currentHeightmap, 9);
            }
            else
            {
                WWW reqMeta = new WWW(url + qs2);
                yield return(reqMeta);

                StartCoroutine(ApplyBingHeightmapV2(reqMeta, key));
            }
        }

        yield return(reqImage);

        //need this to add the texture to the terrain so it looks like a map
        List <SplatPrototype> splatList = new List <SplatPrototype>();
        SplatPrototype        newSplat  = new SplatPrototype();

        newSplat.texture = reqImage.texture;         //satellite: req, heightmap: req2 (use req normally)
        float width = GetComponent <Terrain> ().terrainData.size.x;

        newSplat.tileSize   = new Vector2(width, width);
        newSplat.tileOffset = Vector2.zero;
        splatList.Add(newSplat);
        GetComponent <Terrain> ().terrainData.splatPrototypes = splatList.ToArray();
    }