예제 #1
0
    void OnLocationUpdated(Mapbox.Unity.Location.Location location)
    {
        _locationProvider.OnLocationUpdated -= OnLocationUpdated;

        if (PhotonNetwork.IsMasterClient)
        {
            Hashtable roomSettings = PhotonNetwork.CurrentRoom.CustomProperties;

            _map.Initialize(location.LatitudeLongitude, _map.AbsoluteZoom);

            //Hashtable newRoomSettings = new Hashtable();
            roomSettings.Add("mapLat", location.LatitudeLongitude.x);
            roomSettings.Add("mapLong", location.LatitudeLongitude.y);

            PhotonNetwork.CurrentRoom.SetCustomProperties(roomSettings);
        }
        else
        {
            // Hashtable roomSettings = PhotonNetwork.CurrentRoom.CustomProperties;

            // Vector2d latLong = new Vector2d(
            //     (double) roomSettings["mapLat"],
            //     (double) roomSettings["mapLong"]
            // );
            // _map.Initialize(latLong, _map.AbsoluteZoom);
        }
    }
예제 #2
0
    IEnumerator RunSearch(string url)
    {
        Debug.Log(url);
        UnityWebRequest request = new UnityWebRequest(url, "GET");

        request.downloadHandler = new DownloadHandlerBuffer();
        yield return(request.SendWebRequest());

        Debug.Log(request.responseCode);
        Debug.Log(request.downloadHandler.text);
        Response response = JsonUtility.FromJson <Response>(request.downloadHandler.text);

        Debug.Log(response.results.Length);
        for (int i = 0; i < response.results.Length; i++)
        {
            GameObject obj = Instantiate(resourceLocationData[resourceIndex].MarkerPrefab);
            obj.transform.SetParent(transform.parent);
            //obj.GetComponent<MapMarker>().Init(this, _map, new Mapbox.Utils.Vector2d(response.results[i].geometry.location.lat, response.results[i].geometry.location.lng), response.results[i].name);
            placeMarkers.Add(obj);
        }

        if (!string.IsNullOrEmpty(response.next_page_token))
        {
            yield return(new WaitForSeconds(2));

            Debug.Log(response.next_page_token);
            Mapbox.Unity.Location.Location loc = LocationProviderFactory.Instance.DefaultLocationProvider.CurrentLocation;
            string nextUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + loc.LatitudeLongitude.ToStringInv() + "&radius=" + radius + "&type=" + resourceLocationData[resourceIndex].LocTypes[locationIndex] + "&pagetoken=" + response.next_page_token + "&key=" + apiKey;
            StartCoroutine(RunSearch(nextUrl));
        }
        else
        {
            locationIndex++;
            if (locationIndex >= resourceLocationData[resourceIndex].LocTypes.Length)
            {
                resourceIndex++;
                locationIndex = 0;
            }
            if (resourceIndex < resourceLocationData.Count)
            {
                Mapbox.Unity.Location.Location loc = LocationProviderFactory.Instance.DefaultLocationProvider.CurrentLocation;
                string nextUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + loc.LatitudeLongitude.ToStringInv() + "&radius=" + radius + "&type=" + resourceLocationData[resourceIndex].LocTypes[locationIndex] + "&key=" + apiKey;
                StartCoroutine(RunSearch(nextUrl));
            }
        }
    }
예제 #3
0
 void LateUpdate()
 {
     Mapbox.Unity.Location.Location loc = LocationProviderFactory.Instance.DefaultLocationProvider.CurrentLocation;
     if (_isInitialized && loc.Timestamp > 0 && (!searchHasRun || Vector2d.Distance(lastLoc, Mapbox.Unity.Utilities.Conversions.LatLonToMeters(loc.LatitudeLongitude)) > radius / 2f))
     {
         StopAllCoroutines();
         for (int i = 0; i < placeMarkers.Count; i++)
         {
             Destroy(placeMarkers[i]);
         }
         placeMarkers.Clear();
         string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + loc.LatitudeLongitude.ToStringInv() + "&radius=" + radius + "&type=" + resourceLocationData[resourceIndex].LocTypes[locationIndex] + "&key=" + apiKey;
         StartCoroutine(RunSearch(url));
         lastLoc      = Mapbox.Unity.Utilities.Conversions.LatLonToMeters(loc.LatitudeLongitude);
         searchHasRun = true;
     }
 }
예제 #4
0
    //**THIS FUNCTION QUERIES FOR THE TRAIL NAME AND CREATES THE ACTUAL TRAIL RENDERER LINE**//

    public IEnumerator getDirectionsFromTrailName(WWWHandler www, string trailName, Mapbox.Unity.Location.Location location)
    {
        Debug.Log("Getting trail: " + trailName);

        wwwScript    = www;
        waypointList = new List <Vector2d>();

        //set initialLocation (probably as trail head node) as vec2

        //initialLocation
        Vector3 initLoc = UnityVectorFromVec2d(location.LatitudeLongitude);

        initialLocation = new Vector3(initLoc.x, initLoc.z);

        //store all waypoints as Vec2ds
        CoroutineWithData nodeData = new CoroutineWithData(this, wwwScript.GetTrail(trailName));

        yield return(nodeData.coroutine);

        try{
            JSONNode parsedNode = SimpleJSON.JSON.Parse(nodeData.result.ToString());

            Debug.Log("trail node count: " + parsedNode["geometry"]["coordinates"].Count);

            Debug.Log(parsedNode.ToString());

            for (int i = 0; i < parsedNode["geometry"]["coordinates"].Count; i++)
            {
                double lat = parsedNode["geometry"]["coordinates"][i][1].AsDouble;
                double lon = parsedNode["geometry"]["coordinates"][i][0].AsDouble;

                Vector2d vec2d = new Vector2d(lat, lon);

                waypointList.Add(vec2d);
            }

            //waypoints = new Mapbox.Utils.Vector2d[(waypointList.Count * 2) - 1]; //minus one because you can't calculate midpoint at end
            waypoints = new Vector2d[waypointList.Count];             //1:1 trail
            heights   = new float[waypointList.Count];
            waypoints = waypointList.ToArray();

            //wait for map to load before directions
            StartCoroutine(this.waitForTime(loadTime));
        } catch {}
    }
예제 #5
0
    //** THIS IS FOR THE TEST TRAIL **//
    public IEnumerator getTestDirectionsFromJSON(WWWHandler www, Mapbox.Unity.Location.Location location)
    {
        Debug.Log("Converting JSON to vec2d");

        wwwScript = www;

        waypointList = new List <Vector2d>();


        //initialLocation
        Vector3 initLoc = UnityVectorFromVec2d(location.LatitudeLongitude);

        initialLocation = new Vector3(initLoc.x, initLoc.z);


        CoroutineWithData nodeData = new CoroutineWithData(this, wwwScript.GetTestTrail());

        yield return(nodeData.coroutine);

        JSONNode parsedNode = SimpleJSON.JSON.Parse(nodeData.result.ToString());

        for (int i = 0; i < parsedNode.Count; i++)
        {
            double lat = parsedNode[i] ["Latitude"].AsDouble;
            double lon = parsedNode[i] ["Longitude"].AsDouble;

            Vector2d vec2d = new Vector2d(lat, lon);

            waypointList.Add(vec2d);
        }

        //waypoints = new Mapbox.Utils.Vector2d[(waypointList.Count * 2) - 1]; //minus one because you can't calculate midpoint at end
        waypoints = new Vector2d[waypointList.Count];         //1:1 trail
        heights   = new float[waypointList.Count];
        waypoints = waypointList.ToArray();
        startDirections();
    }