Example #1
0
    private IEnumerator loadRestaurants()
    {
        degreesLongitudeInMetersAtEquator = 111319.9f;
        loadingManager.state = "GPS 신호 수신 중...";
        loadingManager.step  = 30f;
        loadingManager.ToggleUpdateFlag();

        while (!GPSManager.Instance.isReady)
        {
            yield return(new WaitForSeconds(1.0f));
        }

        loadingManager.state = "서버로부터 주변 식당 정보 받는 중...";
        loadingManager.step  = 60f;
        loadingManager.ToggleUpdateFlag();



        //Real GPS Position - This will be the world origin.
        //var gpsLat = "36.1380077";
        //var gpsLon = "128.4166394";
        float[] Lats = new float[5];
        float[] Lons = new float[5];


        float gpsLat = 0.0f;
        float gpsLon = 0.0f;

        for (int i = 0; i < 5; i++)
        {
            Lats[i] = float.Parse(GPSManager.Instance.latitude);
            Lons[i] = float.Parse(GPSManager.Instance.longitude);
        }
        for (int j = 0; j < 5; j++)
        {
            gpsLat = gpsLat + Lats[j];
            gpsLon = gpsLon + Lons[j];
        }

        gpsLat = gpsLat / 5;
        gpsLon = gpsLon / 5;

        dic.Clear();
        dic.Add("url", "restaurants/near2");
        dic.Add("method", "GET");
        dic.Add("lat", gpsLat.ToString());
        dic.Add("lon", gpsLon.ToString());
        dic.Add("email", Login.userId);
        dic.Add("radius", "500");

        //IEnumerator sender = serverManager.SendRequest(dic);
        eventHandler.onClick(this, serverManager.SendRequest(dic), EventHandler.HandlingType.Restaurants);

        while (!flagWakeUp)
        {
            yield return(new WaitForSeconds(1.0f));
        }

        restaurants = eventHandler.result as Dictionary <string, Restaurant>;

        Debug.Log("Count : " + restaurants.Count);
        // GPS position converted into unity coordinates

        GameObject   compassMover = Instantiate(compassMoverData, null);
        CompassMover mover        = compassMover.GetComponent <CompassMover>();


        loadingBar.SetActive(false);
        // 좋은 각도가 나올때까지 대기.
        while (!mover.isGoodDegree)
        {
            yield return(new WaitForSeconds(0.1f));
        }
        // mover 삭제
        mover.isDone = true;
        loadingBar.SetActive(true);

        ToastMaker.instance.ShowToast("Heading : " + GPSManager.Instance.heading);
        foreach (string k in restaurants.Keys)
        {
            Restaurant restaurant = restaurants[k];
            var        latOffset  = (restaurant.y - gpsLat) * degreesLatitudeInMeters;
            var        lonOffset  = (restaurant.x - gpsLon) * GetLongitudeDegreeDistance(restaurant.x);
            Debug.Log("=============");
            Debug.Log("lat : " + gpsLat);
            Debug.Log("lon : " + gpsLon);
            Debug.Log("latOffset : " + latOffset);
            Debug.Log("lonOffset : " + lonOffset);
            Debug.Log("=============");

            //var distance = gpsCalc.distance(float.Parse(gpsLat), float.Parse(gpsLon), restaurant.y, restaurant.x);
            //var degree = gpsCalc.bearingP1toP2(float.Parse(gpsLat), float.Parse(gpsLon), restaurant.y, restaurant.x);
            Vector3 vector3 = new Vector3(latOffset, 0, lonOffset);

            //Vector3 vector3 = Vector3.forward * (float)distance;

            //Quaternion qRotate = Quaternion.Euler(0f, 180, 0f);
            //vector3 = qRotate * vector3;

            //heading = Quaternion.LookRotation(Camera.main.transform.TransformDirection(GPSManager.Instance.headingVector)).eulerAngles.y;


            //vector3 = Quaternion.AngleAxis(degree, Vector3.up) * vector3;


            if (vector3.magnitude < 100.0f)
            {
                vector3.y = -20.0f;
            }
            else if (vector3.magnitude < 150.0f)
            {
                vector3.y = 10.0f;
            }
            else if (vector3.magnitude < 200.0f)
            {
                vector3.y = 40.0f;
            }
            else if (vector3.magnitude < 250.0f)
            {
                vector3.y = 90.0f;
            }
            else if (vector3.magnitude < 300.0f)
            {
                vector3.y = 150.0f;
            }
            else if (vector3.magnitude < 350.0f)
            {
                vector3.y = 220.0f;
            }
            else if (vector3.magnitude < 400.0f)
            {
                vector3.y = 310.0f;
            }
            else if (vector3.magnitude < 450.0f)
            {
                vector3.y = 380.0f;
            }
            else
            {
                vector3.y = 460.0f;
            }

            Debug.Log(vector3);

            vectors.Add(vector3);
        }
        Destroy(loadingBar.gameObject);
        Draw();
        //yield return new WaitUntil(() => flagWakeUp == true);
    }
Example #2
0
    private IEnumerator loadRestaurantsWithCondition()
    {
        degreesLongitudeInMetersAtEquator = 111319.9f;

        loadingBar = Instantiate(loadingBarData, canvas.transform);
        loadingBar.SetActive(true);
        loadingManager       = loadingBar.transform.Find("vica").gameObject.GetComponent <LoadingManager>();
        loadingManager.state = "서버로부터 해당 조건의 식당 정보 탐색 중...";
        loadingManager.step  = 90f;
        loadingManager.ToggleUpdateFlag();

        float[] Lats = new float[5];
        float[] Lons = new float[5];


        float gpsLat = 0.0f;
        float gpsLon = 0.0f;

        for (int i = 0; i < 5; i++)
        {
            Lats[i] = float.Parse(GPSManager.Instance.latitude);
            Lons[i] = float.Parse(GPSManager.Instance.longitude);
        }
        for (int j = 0; j < 5; j++)
        {
            gpsLat = gpsLat + Lats[j];
            gpsLon = gpsLon + Lons[j];
        }

        gpsLat = gpsLat / 5;
        gpsLon = gpsLon / 5;

        dic.Clear();
        dic.Add("url", "restaurants/research");
        dic.Add("method", "GET");
        dic.Add("lat", gpsLat.ToString());
        dic.Add("lon", gpsLon.ToString());
        dic.Add("mood", mood);
        dic.Add("category", category);
        dic.Add("radius", "500");

        flagWakeUp = false;
        eventHandler.onClick(this, serverManager.SendRequest(dic), EventHandler.HandlingType.Restaurants);

        while (!flagWakeUp)
        {
            yield return(new WaitForSeconds(1.0f));
        }

        if (eventHandler.result is Dictionary <string, Restaurant> )
        {
            restaurants = eventHandler.result as Dictionary <string, Restaurant>;
            foreach (string k in restaurants.Keys)
            {
                Restaurant restaurant = restaurants[k];
                var        latOffset  = (restaurant.y - gpsLat) * degreesLatitudeInMeters;
                var        lonOffset  = (restaurant.x - gpsLon) * GetLongitudeDegreeDistance(restaurant.x);
                Debug.Log("=============");
                Debug.Log("lat : " + gpsLat);
                Debug.Log("lon : " + gpsLon);
                //ToastMaker.instance.ShowToast("Lat : " + gpsLat + ", Lon : " + gpsLon);
                //ToastMaker.instance.ShowToast("LatOffset : " + latOffset + ", LonOffset : " + lonOffset);
                Debug.Log("latOffset : " + latOffset);
                Debug.Log("lonOffset : " + lonOffset);
                Debug.Log("=============");

                //var distance = gpsCalc.distance(float.Parse(gpsLat), float.Parse(gpsLon), restaurant.y, restaurant.x);
                //var degree = gpsCalc.bearingP1toP2(float.Parse(gpsLat), float.Parse(gpsLon), restaurant.y, restaurant.x);
                Vector3 vector3 = new Vector3(latOffset, 0, lonOffset);

                //Vector3 vector3 = Vector3.forward * (float)distance;

                //Quaternion qRotate = Quaternion.Euler(0f, degree-180, 0f);
                //vector3 = qRotate * vector3;

                //heading = Quaternion.LookRotation(Camera.main.transform.TransformDirection(GPSManager.Instance.headingVector)).eulerAngles.y;


                //vector3 = Quaternion.AngleAxis((-GPSManager.Instance., Vector3.up) * vector3;


                if (vector3.magnitude < 100.0f)
                {
                    vector3.y = -20.0f;
                }
                else if (vector3.magnitude < 150.0f)
                {
                    vector3.y = 10.0f;
                }
                else if (vector3.magnitude < 200.0f)
                {
                    vector3.y = 40.0f;
                }
                else if (vector3.magnitude < 250.0f)
                {
                    vector3.y = 90.0f;
                }
                else if (vector3.magnitude < 300.0f)
                {
                    vector3.y = 150.0f;
                }
                else if (vector3.magnitude < 350.0f)
                {
                    vector3.y = 220.0f;
                }
                else if (vector3.magnitude < 400.0f)
                {
                    vector3.y = 310.0f;
                }
                else if (vector3.magnitude < 450.0f)
                {
                    vector3.y = 380.0f;
                }
                else
                {
                    vector3.y = 460.0f;
                }


                Debug.Log(vector3);

                vectors.Add(vector3);
            }
            Destroy(loadingBar.gameObject);
            Draw();
        }
        else
        {
            // 에러
            ToastMaker.instance.ShowToast("로딩 중 문제가 발생하였습니다. 다시 시도해주세요.");
            Destroy(loadingBar.gameObject);
        }
    }