コード例 #1
0
ファイル: Sidebar.cs プロジェクト: morbidintel/WebCity
    IEnumerator GetTravelTimesCoroutine(IEnumerable <Place> places)
    {
        string[] placeIDs = places.Select(p => p.googleid).ToArray();
        WWW      www      = new WWW(PHPProxy.Escape(DistanceMatrix.BuildURL(placeIDs, placeIDs)));

        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
            yield break;
        }

        DistanceMatrix dm = new DistanceMatrix();

        dm = JsonUtility.FromJson <DistanceMatrix>(www.text);

        if (dm.status != "OK")
        {
            Debug.Log(dm.error_message);
            yield break;
        }

        for (int i = 0; i < places.Count(); ++i)
        {
            dm.origin_addresses[i] = dm.destination_addresses[i] = places.ElementAt(i).googleid;
        }

        currentDistanceMatrix = dm;
    }
コード例 #2
0
ファイル: Sidebar.cs プロジェクト: morbidintel/WebCity
    IEnumerator GetPlaceCoroutine(string place_id)
    {
        WWW www = new WWW(PHPProxy.Escape(PlaceDetails.BuildURL(
                                              place_id,
                                              PlaceDetails.Fields.name |
                                              PlaceDetails.Fields.geometry |
                                              PlaceDetails.Fields.place_id)));

        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
            yield break;
        }

        PlaceDetails place = JsonUtility.FromJson <PlaceDetails>(www.text);

        if (place.status != "OK")
        {
            Debug.Log(place.error_message);
            yield break;
        }

        MapTagManager.Instance.ShowPlaceOnMap(place);
    }
コード例 #3
0
ファイル: MapSearch.cs プロジェクト: morbidintel/WebCity
    IEnumerator AutocompleteCoroutine(string value)
    {
        yield return(new WaitForSecondsRealtime(.5f));

        if (value != "")
        {
            string url = string.Format(QueryAutocomplete.URL + "&location={1}&radius={2}",
                                       WWW.EscapeURL(value),
                                       MapCamera.Instance.GetCameraCoords().ToString(),
                                       MapCamera.Instance.GetRadius());
            WWW www = new WWW(PHPProxy.Escape(url));
            yield return(www);

            if (www.error != null)
            {
                Debug.Log(www.error);
                yield break;
            }

            result = JsonUtility.FromJson <QueryAutocomplete>(www.text);

            if (result.status != "OK")
            {
                Debug.Log(result.error_message);
                yield break;
            }
        }
        else
        {
            result = null;
        }

        ClearDropdown();
        if (result != null)
        {
            AddItems(result);
        }
        if (isSearchSelected)
        {
            ShowDropdown();
        }

        input.MoveTextEnd(false);

        coroutine = null;
    }
コード例 #4
0
    IEnumerator GetPlaceCoroutine(string place_id)
    {
        if (place_id == "")
        {
            yield break;
        }

        // do we need to retrieve Place Details?
        if (data.placeDetails == null || place_id != data.placeDetails.result.place_id)
        {
            WWW www = new WWW(PHPProxy.Escape(PlaceDetails.BuildURL(place_id,
                                                                    PlaceDetails.Fields.name | PlaceDetails.Fields.geometry |
                                                                    PlaceDetails.Fields.photo | PlaceDetails.Fields.place_id)));
            yield return(www);

            if (www.error != null)
            {
                Debug.Log(www.error);
                yield break;
            }

            data.placeDetails = JsonUtility.FromJson <PlaceDetails>(www.text);
        }

        if (data.placeDetails.status != "OK")
        {
            Debug.Log(data.placeDetails.error_message);
            yield break;
        }

        nameLabel.text = gameObject.name = data.placeDetails.result.name;

        yield return(GetTravelTimes());

        data.pos = MapCamera.LatLongToUnity(data.placeDetails.result.geometry.location);
        // create a map tag on the world map
        mapTag    = MapTagManager.Instance.ShowPlaceOnMap(data.placeDetails);
        IsLoading = false;         // done with loading
    }
コード例 #5
0
ファイル: MapSearch.cs プロジェクト: morbidintel/WebCity
    IEnumerator ShowPlaceSearchCoroutine(string keyword)
    {
        string url = NearbySearch.BuildURL(
            MapCamera.UnityToLatLong(MapCamera.Instance.TargetPosition),
            MapCamera.Instance.TargetDistance * 1000f,
            keyword);
        WWW www = new WWW(PHPProxy.Escape(url));

        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
            yield break;
        }

        Debug.Log(url);
        Debug.Log(www.text);
        NearbySearch nearby = JsonUtility.FromJson <NearbySearch>(www.text);

        if (nearby.status != "OK")
        {
            Debug.Log(nearby.error_message);
            yield break;
        }

        currentTags.ForEach(t => MapTagManager.Instance.ClearMapTag(t));
        currentTags.Clear();

        foreach (var result in nearby.results)
        {
            currentTags.Add(MapTagManager.Instance.ShowPlaceOnMap(result.geometry.location, result.name));
        }

        coroutine = null;
    }
コード例 #6
0
ファイル: MapSearch.cs プロジェクト: morbidintel/WebCity
    IEnumerator GoToPlaceCoroutine(string place_id)
    {
        WWW www = new WWW(PHPProxy.Escape(PlaceDetails.BuildURL(place_id,
                                                                PlaceDetails.Fields.name |
                                                                PlaceDetails.Fields.geometry |
                                                                PlaceDetails.Fields.place_id)));

        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
            yield break;
        }

        PlaceDetails place = JsonUtility.FromJson <PlaceDetails>(www.text);

        if (place.status != "OK")
        {
            Debug.Log(place.error_message);
            yield break;
        }

        if (place?.result?.geometry != null)
        {
            MapCamera.Instance.SetCameraViewport(place.result.geometry);
        }
        EventSystem.current.SetSelectedGameObject(null);

        currentTags.ForEach(t => MapTagManager.Instance.ClearMapTag(t));
        currentTags.Clear();

        currentTags.Add(MapTagManager.Instance.ShowPlaceOnMap(place));

        coroutine = null;
    }
コード例 #7
0
    IEnumerator GetDetails(string place_id)
    {
        WWW www;

        PlaceDetails.Result result = currentPlace?.data.placeDetails.result;
        if (result == null ||
            result.formatted_address == null || result.formatted_address == "" ||
            result.website == null || result.website == "" ||
            result.international_phone_number == null || result.international_phone_number == "" ||
            result.opening_hours.weekday_text == null)
        {
            www = new WWW(PHPProxy.Escape(PlaceDetails.BuildURL(
                                              place_id,
                                              PlaceDetails.Fields.formatted_address |
                                              PlaceDetails.Fields.website |
                                              PlaceDetails.Fields.international_phone_number |
                                              PlaceDetails.Fields.opening_hours)));
            yield return(www);

            if (www.error != null)
            {
                Debug.Log(www.error);
                yield break;
            }

            PlaceDetails place = JsonUtility.FromJson <PlaceDetails>(www.text);

            if (place.status != "OK")
            {
                Debug.Log(place.error_message);
                yield break;
            }

            result = place.result;
        }

        addressGroup.SetActive(result.formatted_address != null && result.formatted_address != "");
        if (addressGroup.activeInHierarchy)
        {
            addressText.text = result.formatted_address;
        }

        websiteGroup.SetActive(result.website != null && result.website != "");
        if (websiteGroup.activeInHierarchy)
        {
            websiteText.text = new Regex(@"^(?:https?:\/\/)?(?:www\.)?")
                               .Replace(result.website, "")
                               .TrimEnd('/');
        }

        phoneGroup.SetActive(result.international_phone_number != null && result.international_phone_number != "");
        if (phoneGroup.activeInHierarchy)
        {
            phoneText.text = result.international_phone_number;
        }

        hoursGroup.SetActive(result.opening_hours.weekday_text != null);
        if (hoursGroup.activeInHierarchy)
        {
            string hourstext =
                result.opening_hours.weekday_text[((int)DateTime.Now.DayOfWeek + 6) % 7];
            hourstext      = new Regex(@"^.{6,9}: ").Replace(hourstext, "");
            hoursText.text = result.opening_hours.open_now ?
                             "Open now: " + hourstext : "<color=red>Closed</color>";
        }

        LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponentInChildren <ScrollRect>().content);
        Sidebar.Instance.GoToPage(Sidebar.Page.PlaceDetails);
        IsLoading = false;
    }
コード例 #8
0
    IEnumerator GetPhotos(string place_id)
    {
        WWW    www;
        string photo_reference = "";

        if (currentPlace?.data.placeDetails.result.photos == null)
        {
            www = new WWW(PHPProxy.Escape(PlaceDetails.BuildURL(
                                              place_id,
                                              PlaceDetails.Fields.photo |
                                              PlaceDetails.Fields.place_id)));
            yield return(www);

            if (www.error != null)
            {
                Debug.Log(www.error);
                yield break;
            }

            PlaceDetails place = JsonUtility.FromJson <PlaceDetails>(www.text);

            if (place.status != "OK")
            {
                Debug.Log(place.error_message);
                yield break;
            }

            if (place.result?.photos == null ||
                place.result?.photos.Length == 0)
            {
                yield break;
            }

            photo_reference = place.result.photos[0].photo_reference;
        }
        else if (currentPlace.data.placeDetails.result.photos.Length == 0)
        {
            yield break;
        }
        else
        {
            photo_reference = currentPlace.data.placeDetails.result.photos[0].photo_reference;
        }

        www = new WWW(PHPProxy.Escape(PlacePhotos.BuildURL(
                                          photo_reference,
                                          (int)this.RectTransform().rect.width, 0)));
        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
            yield break;
        }

        Rect rect = new Rect(0, 0, www.texture.width, www.texture.height);

        currentPhoto.rectTransform.sizeDelta = rect.size;
        currentPhoto.color  = Color.white;
        currentPhoto.name   = photo_reference;
        currentPhoto.sprite = Sprite.Create(www.texture, rect, new Vector2(.5f, .5f));
        photoHolder.SetActive(true);
    }