/* INFINITY CODE 2013-2019 */ /* http://www.infinity-code.com */ using System; using System.Collections.Generic; using InfinityCode.RealWorldTerrain.XML; using UnityEngine; namespace InfinityCode.RealWorldTerrain.Webservices.Results { /// /// Result of Google Maps Places query. /// public class RealWorldTerrainPlacesResult { /// /// Coordinates of the place. /// public Vector2 location; /// /// URL of a recommended icon which may be displayed to the user when indicating this result. /// public string icon; /// /// Unique stable identifier denoting this place. \n /// This identifier may not be used to retrieve information about this place, but is guaranteed to be valid across sessions. \n /// It can be used to consolidate data about this place, and to verify the identity of a place across separate searches. \n /// Note: The id is now deprecated in favor of place_id. /// public string id; /// /// Human-readable address of this place. \n /// Often this address is equivalent to the "postal address". \n /// The formatted_address property is only returned for a Text Search. /// public string formatted_address; /// /// Human-readable name for the returned result. \n /// For establishment results, this is usually the business name. /// public string name; /// /// Unique identifier for a place. /// public string place_id; /// /// Unique token that you can use to retrieve additional information about this place in a Place Details request. \n /// Although this token uniquely identifies the place, the converse is not true. \n /// A place may have many valid reference tokens. \n /// It's not guaranteed that the same token will be returned for any given place across different searches. \n /// Note: The reference is now deprecated in favor of place_id. /// public string reference; /// /// Array of feature types describing the given result. \n /// XML responses include multiple type elements if more than one type is assigned to the result. /// public string[] types; /// /// Feature name of a nearby location. \n /// Often this feature refers to a street or neighborhood within the given results. \n /// The vicinity property is only returned for a Nearby Search. /// public string vicinity; /// /// The price level of the place, on a scale of 0 to 4. \n /// The exact amount indicated by a specific value will vary from region to region. \n /// Price levels are interpreted as follows: \n /// -1 - Unknown \n /// 0 - Free \n /// 1 - Inexpensive \n /// 2 - Moderate \n /// 3 - Expensive \n /// 4 - Very Expensive /// public int price_level = -1; /// /// Place's rating, from 1.0 to 5.0, based on aggregated user reviews. /// public float rating; /// /// Value indicating if the place is open at the current time. /// public bool open_now; /// /// Indicates the scope of the place_id. /// public string scope; /// /// Undocumented in Google Maps Places API. /// public string[] weekday_text; /// /// Array of photo objects, each containing a reference to an image. \n /// A Place Search will return at most one photo object. \n /// Performing a Place Details request on the place may return up to ten photos. /// public Photo[] photos; public RealWorldTerrainPlacesResult() { } /// /// Constructor /// /// Place node from response public RealWorldTerrainPlacesResult(RealWorldTerrainXML node) { List photos = new List(); List types = new List(); List weekday_text = new List(); foreach (RealWorldTerrainXML n in node) { if (n.name == "name") name = n.Value(); else if (n.name == "id") id = n.Value(); else if (n.name == "vicinity") vicinity = n.Value(); else if (n.name == "type") types.Add(n.Value()); else if (n.name == "geometry") location = RealWorldTerrainXML.GetVector2FromNode(n[0]); else if (n.name == "rating") rating = n.Value(); else if (n.name == "icon") icon = n.Value(); else if (n.name == "reference") reference = n.Value(); else if (n.name == "place_id") place_id = n.Value(); else if (n.name == "scope") scope = n.Value(); else if (n.name == "price_level") price_level = n.Value(); else if (n.name == "formatted_address") formatted_address = n.Value(); else if (n.name == "opening_hours") { open_now = n.Get("open_now") == "true"; foreach (RealWorldTerrainXML wdt in n.FindAll("weekday_text")) weekday_text.Add(wdt.Value()); } else if (n.name == "photo") { photos.Add(new Photo(n)); } else Debug.Log(n.name); } this.photos = photos.ToArray(); this.types = types.ToArray(); this.weekday_text = weekday_text.ToArray(); } /// /// Photo objects, contains a reference to an image. /// public class Photo { /// /// The maximum width of the image. /// public int width; /// /// The maximum height of the image. /// public int height; /// /// String used to identify the photo when you perform a Photo request. /// public string photo_reference; /// /// Contains any required attributions. This field will always be present, but may be empty. /// public string[] html_attributions; public Photo() { } /// /// Constructor /// /// Photo node from response public Photo(RealWorldTerrainXML node) { try { width = node.Get("width"); height = node.Get("height"); photo_reference = node["photo_reference"].Value(); List html_attributions = new List(); foreach (RealWorldTerrainXML ha in node.FindAll("html_attributions")) html_attributions.Add(ha.Value()); this.html_attributions = html_attributions.ToArray(); } catch (Exception) { } } /// /// Download photo from Google Places. /// /// Google Maps API Key. /// /// Specifies the maximum desired width, in pixels, of the image returned by the Place Photos service. \n /// If the image is smaller than the values specified, the original image will be returned. \n /// If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, restricted to its original aspect ratio. \n /// maxWidth accept an integer between 1 and 1600. /// /// /// Specifies the maximum desired height, in pixels, of the image returned by the Place Photos service. \n /// If the image is smaller than the values specified, the original image will be returned. \n /// If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, restricted to its original aspect ratio. \n /// maxHeight accept an integer between 1 and 1600.\n /// /// public RealWorldTerrainGooglePlacePhoto Download(string key, int? maxWidth = null, int? maxHeight = null) { if (!maxWidth.HasValue) maxWidth = width; if (!maxHeight.HasValue) maxHeight = height; return RealWorldTerrainGooglePlacePhoto.Download(key, photo_reference, maxWidth, maxHeight); } } } }