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); }
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 }
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; }
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; }
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); }