Exemple #1
0
        public IEnumerator LoadPlaces(string url)            //Request the API
        {
            Debug.Log("GO4Square URL: " + url);

            var www = new WWW(url);

            yield return(www);

            ParseJob job = new ParseJob();

            job.InData = www.text;
            job.Start();

            yield return(StartCoroutine(job.WaitFor()));

            IDictionary response = (IDictionary)((IDictionary)job.OutData)["response"];
            IList       results  = (IList)response ["venues"];

            foreach (Transform child in transform)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (IDictionary result in results)              //This example only takes GPS location and the name of the object. There's lot more, take a look at the Foursquare API documentation

            {
                IDictionary location = ((IDictionary)result ["location"]);
                double      lat      = (double)location ["lat"];
                double      lng      = (double)location ["lng"];


                Coordinates coordinates = new Coordinates(lat, lng, 0);
                GameObject  go          = GameObject.Instantiate(prefab);
                Vector3     pos         = coordinates.convertCoordinateToVector(0);

                if (goMap.useElevation)
                {
                    pos = GOMap.AltitudeToPoint(pos);
                }

                go.transform.localPosition = pos;

                go.transform.parent = transform;
                go.name             = (string)result["name"];
            }
        }
        //Draws a line given a list of latitudes/longitudes
        public GameObject dropLine(List <Coordinates> polyline, float width, float height, Material material, GOUVMappingStyle uvMappingStyle)
        {
            List <Vector3> converted = new List <Vector3> ();

            foreach (Coordinates coordinates in polyline)
            {
                Vector3 v = coordinates.convertCoordinateToVector();
                if (useElevation)
                {
                    v = GOMap.AltitudeToPoint(v);
                }

                converted.Add(v);
            }

            return(dropLine(converted, width, height, material, uvMappingStyle));
        }
        //Draws a polygon given a list of latitudes/longitudes that is a closed shape
        public GameObject dropPolygon(List <Coordinates> shape, float height, Material material, GOUVMappingStyle uvMappingStyle)
        {
            List <Vector3> converted = new List <Vector3> ();

            foreach (Coordinates coordinates in shape)
            {
                Vector3 v = coordinates.convertCoordinateToVector();
                if (useElevation)
                {
                    v = GOMap.AltitudeToPoint(v);
                }

                converted.Add(v);
            }

            if (!GOFeature.IsClockwise(converted))
            {
                converted.Reverse();
            }

            return(dropPolygon(converted, height, material, uvMappingStyle));
        }
Exemple #4
0
        IEnumerator NearbySearch(GOTile tile)
        {
            //Center of the map tile
            Coordinates tileCenter = tile.goTile.tileCenter;

            //radius of the request, equals the tile diagonal /2
            float radius = tile.goTile.diagonalLenght / 2;

            //The complete nearby search url, api key is added at the end
            string url = nearbySearchUrl + "location=" + tile.goTile.tileCenter.latitude + "," + tile.goTile.tileCenter.longitude + "&radius=" + radius + "&type=" + type + "&key=" + googleAPIkey;

            //Perform the request
            var www = UnityWebRequest.Get(url);

            yield return(www.SendWebRequest());

            //Check for errors
            if (string.IsNullOrEmpty(www.error))
            {
                string response = www.downloadHandler.text;
                //Deserialize the json response
                IDictionary deserializedResponse = (IDictionary)Json.Deserialize(response);

                Debug.Log(string.Format("[GO Places] Tile center: {0} - Request Url {1} - response {2}", tileCenter.toLatLongString(), url, response));

                //That's our list of Places
                IList results = (IList)deserializedResponse ["results"];

                //Create a container for the places and set it as a tile child. In this way when the tile is destroyed it will take also the places with it.
                GameObject placesContainer = new GameObject("Places");
                placesContainer.transform.SetParent(tile.transform);

                foreach (IDictionary result in results)
                {
                    string placeID = (string)result["place_id"];
                    string name    = (string)result["name"];

                    IDictionary location = (IDictionary)((IDictionary)result ["geometry"])["location"];
                    double      lat      = (double)location ["lat"];
                    double      lng      = (double)location ["lng"];

                    //Create a new coordinate object, with the desired lat lon
                    Coordinates coordinates = new Coordinates(lat, lng, 0);

                    if (!TileFilter(tile, coordinates))
                    {
                        continue;
                    }

                    //Instantiate your game object
                    GameObject place = GameObject.Instantiate(prefab);
                    place.SetActive(true);
                    //Convert coordinates to position
                    Vector3 position = coordinates.convertCoordinateToVector(place.transform.position.y);

                    if (goMap.useElevation)
                    {
                        position = GOMap.AltitudeToPoint(position);
                    }

                    //Set the position to object
                    place.transform.localPosition = position;
                    //the parent
                    place.transform.SetParent(placesContainer.transform);
                    //and the name
                    place.name = (name != null && name.Length > 0)? name:placeID;

                    if (addGOPlaceComponent)
                    {
                        GOPlacesPrefab component = place.AddComponent <GOPlacesPrefab> ();
                        component.placeInfo = result;
                        component.goPlaces  = this;
                    }
                }
            }
        }