RealWorldTerrainGooglePlaces.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /* INFINITY CODE 2013-2019 */
  2. /* http://www.infinity-code.com */
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using InfinityCode.RealWorldTerrain.ExtraTypes;
  7. using InfinityCode.RealWorldTerrain.Webservices.Base;
  8. using InfinityCode.RealWorldTerrain.Webservices.Results;
  9. using InfinityCode.RealWorldTerrain.XML;
  10. using UnityEngine;
  11. namespace InfinityCode.RealWorldTerrain.Webservices
  12. {
  13. /// <summary>
  14. /// The Google Places API allows you to query for place information on a variety of categories, such as: establishments, prominent points of interest, geographic locations, and more. \n
  15. /// You can search for places either by proximity or a text string. \n
  16. /// A Place Search returns a list of places along with summary information about each place.\n
  17. /// https://developers.google.com/places/web-service/search
  18. /// </summary>
  19. public class RealWorldTerrainGooglePlaces : RealWorldTerrainTextWebServiceBase
  20. {
  21. protected RealWorldTerrainGooglePlaces(string key, RequestParams p)
  22. {
  23. _status = RequestStatus.downloading;
  24. StringBuilder url = new StringBuilder();
  25. url.AppendFormat("https://maps.googleapis.com/maps/api/place/{0}/xml?sensor=false", p.typePath);
  26. if (!string.IsNullOrEmpty(key)) url.Append("&key=").Append(key);
  27. p.AppendParams(url);
  28. www = new RealWorldTerrainWWW(url.ToString());
  29. www.OnComplete += OnRequestComplete;
  30. }
  31. /// <summary>
  32. /// A Nearby Search lets you search for places within a specified area. \n
  33. /// You can refine your search request by supplying keywords or specifying the type of place you are searching for.
  34. /// </summary>
  35. /// <param name="lnglat">The longitude/latitude around which to retrieve place information. </param>
  36. /// <param name="radius">
  37. /// Defines the distance (in meters) within which to return place results. \n
  38. /// The maximum allowed radius is 50 000 meters.
  39. /// </param>
  40. /// <param name="key">
  41. /// Your application's API key. \n
  42. /// This key identifies your application for purposes of quota management and so that places added from your application are made immediately available to your app. \n
  43. /// Visit the Google APIs Console to create an API Project and obtain your key.
  44. /// </param>
  45. /// <param name="keyword">A term to be matched against all content that Google has indexed for this place, including but not limited to name, type, and address, as well as customer reviews and other third-party content.</param>
  46. /// <param name="name">
  47. /// One or more terms to be matched against the names of places, separated with a space character. \n
  48. /// Results will be restricted to those containing the passed name values. \n
  49. /// Note that a place may have additional names associated with it, beyond its listed name. \n
  50. /// The API will try to match the passed name value against all of these names. \n
  51. /// As a result, places may be returned in the results whose listed names do not match the search term, but whose associated names do.
  52. /// </param>
  53. /// <param name="types">
  54. /// Restricts the results to places matching at least one of the specified types. \n
  55. /// Types should be separated with a pipe symbol (type1|type2|etc).\n
  56. /// See the list of supported types:\n
  57. /// https://developers.google.com/places/documentation/supported_types
  58. /// </param>
  59. /// <param name="minprice">
  60. /// Restricts results to only those places within the specified range. \n
  61. /// Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. \n
  62. /// The exact amount indicated by a specific value will vary from region to region.
  63. /// </param>
  64. /// <param name="maxprice">
  65. /// Restricts results to only those places within the specified range. \n
  66. /// Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. \n
  67. /// The exact amount indicated by a specific value will vary from region to region.
  68. /// </param>
  69. /// <param name="opennow">
  70. /// Returns only those places that are open for business at the time the query is sent. \n
  71. /// Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
  72. /// </param>
  73. /// <param name="rankBy">Specifies the order in which results are listed.</param>
  74. /// <returns>Query instance to the Google API.</returns>
  75. public static RealWorldTerrainGooglePlaces FindNearby(Vector2 lnglat, int radius, string key, string keyword = null, string name = null, string types = null, int minprice = -1, int maxprice = -1, bool opennow = false, RankBy rankBy = RankBy.prominence)
  76. {
  77. NearbyParams p = new NearbyParams(lnglat, radius)
  78. {
  79. keyword = keyword,
  80. name = name,
  81. types = types,
  82. };
  83. if (minprice != -1) p.minprice = minprice;
  84. if (maxprice != -1) p.maxprice = maxprice;
  85. if (opennow) p.opennow = true;
  86. if (rankBy != RankBy.prominence) p.rankBy = rankBy;
  87. return new RealWorldTerrainGooglePlaces(key, p);
  88. }
  89. /// <summary>
  90. /// A Nearby Search lets you search for places within a specified area. \n
  91. /// You can refine your search request by supplying keywords or specifying the type of place you are searching for.
  92. /// </summary>
  93. /// <param name="key">
  94. /// Your application's API key. \n
  95. /// This key identifies your application for purposes of quota management and so that places added from your application are made immediately available to your app. \n
  96. /// Visit the Google APIs Console to create an API Project and obtain your key.
  97. /// </param>
  98. /// <param name="p">The object containing the request parameters.</param>
  99. /// <returns>Query instance to the Google API.</returns>
  100. public static RealWorldTerrainGooglePlaces FindNearby(string key, NearbyParams p)
  101. {
  102. return new RealWorldTerrainGooglePlaces(key, p);
  103. }
  104. /// <summary>
  105. /// Returns information about a set of places based on a string — for example "pizza in New York" or "shoe stores near Ottawa". \n
  106. /// The service responds with a list of places matching the text string and any location bias that has been set. \n
  107. /// The search response will include a list of places.
  108. /// </summary>
  109. /// <param name="query">
  110. /// The text string on which to search, for example: "restaurant". \n
  111. /// The Google Places service will return candidate matches based on this string and order the results based on their perceived relevance.
  112. /// </param>
  113. /// <param name="key">
  114. /// Your application's API key. \n
  115. /// This key identifies your application for purposes of quota management and so that places added from your application are made immediately available to your app. \n
  116. /// Visit the Google APIs Console to create an API Project and obtain your key.
  117. /// </param>
  118. /// <param name="lnglat">The longitude/latitude around which to retrieve place information.</param>
  119. /// <param name="radius">
  120. /// Defines the distance (in meters) within which to bias place results. \n
  121. /// The maximum allowed radius is 50 000 meters. \n
  122. /// Results inside of this region will be ranked higher than results outside of the search circle; however, prominent results from outside of the search radius may be included.
  123. /// </param>
  124. /// <param name="language">The language code, indicating in which language the results should be returned, if possible. </param>
  125. /// <param name="types">
  126. /// Restricts the results to places matching at least one of the specified types. \n
  127. /// Types should be separated with a pipe symbol (type1|type2|etc). \n
  128. /// See the list of supported types:\n
  129. /// https://developers.google.com/maps/documentation/places/supported_types
  130. /// </param>
  131. /// <param name="minprice">
  132. /// Restricts results to only those places within the specified price level. \n
  133. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  134. /// The exact amount indicated by a specific value will vary from region to region.
  135. /// </param>
  136. /// <param name="maxprice">
  137. /// Restricts results to only those places within the specified price level. \n
  138. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  139. /// The exact amount indicated by a specific value will vary from region to region.
  140. /// </param>
  141. /// <param name="opennow">
  142. /// Returns only those places that are open for business at the time the query is sent. \n
  143. /// Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
  144. /// </param>
  145. /// <returns>Query instance to the Google API.</returns>
  146. public static RealWorldTerrainGooglePlaces FindText(string query, string key, Vector2 lnglat = default(Vector2), int radius = -1, string language = null, string types = null, int minprice = -1, int maxprice = -1, bool opennow = false)
  147. {
  148. TextParams p = new TextParams(query)
  149. {
  150. language = language,
  151. types = types,
  152. };
  153. if (lnglat != default(Vector2)) p.lnglat = lnglat;
  154. if (radius != -1) p.radius = radius;
  155. if (minprice != -1) p.minprice = minprice;
  156. if (maxprice != -1) p.maxprice = maxprice;
  157. if (opennow) p.opennow = true;
  158. return new RealWorldTerrainGooglePlaces(key, p);
  159. }
  160. /// <summary>
  161. /// Returns information about a set of places based on a string — for example "pizza in New York" or "shoe stores near Ottawa". \n
  162. /// The service responds with a list of places matching the text string and any location bias that has been set. \n
  163. /// The search response will include a list of places.
  164. /// </summary>
  165. /// <param name="key">
  166. /// Your application's API key. \n
  167. /// This key identifies your application for purposes of quota management and so that places added from your application are made immediately available to your app. \n
  168. /// Visit the Google APIs Console to create an API Project and obtain your key.
  169. /// </param>
  170. /// <param name="p">The object containing the request parameters.</param>
  171. /// <returns>Query instance to the Google API.</returns>
  172. public static RealWorldTerrainGooglePlaces FindText(string key, TextParams p)
  173. {
  174. return new RealWorldTerrainGooglePlaces(key, p);
  175. }
  176. /// <summary>
  177. /// The Google Places API Radar Search Service allows you to search for up to 200 places at once, but with less detail than is typically returned from a Text Search or Nearby Search request. \n
  178. /// With Radar Search, you can create applications that help users identify specific areas of interest within a geographic area.
  179. /// </summary>
  180. /// <param name="lnglat">The longitude/latitude around which to retrieve place information.</param>
  181. /// <param name="radius">
  182. /// Defines the distance (in meters) within which to return place results. \n
  183. /// The maximum allowed radius is 50 000 meters.
  184. /// </param>
  185. /// <param name="key">
  186. /// Your application's API key. \n
  187. /// This key identifies your application for purposes of quota management and so that places added from your application are made immediately available to your app. \n
  188. /// Visit the Google APIs Console to create an API Project and obtain your key.
  189. /// </param>
  190. /// <param name="keyword">A term to be matched against all content that Google has indexed for this place, including but not limited to name, type, and address, as well as customer reviews and other third-party content.</param>
  191. /// <param name="name">
  192. /// One or more terms to be matched against the names of places, separated by a space character. \n
  193. /// Results will be restricted to those containing the passed name values. \n
  194. /// Note that a place may have additional names associated with it, beyond its listed name. \n
  195. /// The API will try to match the passed name value against all of these names. \n
  196. /// As a result, places may be returned in the results whose listed names do not match the search term, but whose associated names do.
  197. /// </param>
  198. /// <param name="types">
  199. /// Restricts the results to places matching at least one of the specified types. \n
  200. /// Types should be separated with a pipe symbol (type1|type2|etc). \n
  201. /// See the list of supported types:\n
  202. /// https://developers.google.com/maps/documentation/places/supported_types
  203. /// </param>
  204. /// <param name="minprice">
  205. /// Restricts results to only those places within the specified price level. \n
  206. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  207. /// The exact amount indicated by a specific value will vary from region to region.
  208. /// </param>
  209. /// <param name="maxprice">
  210. /// Restricts results to only those places within the specified price level. \n
  211. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  212. /// The exact amount indicated by a specific value will vary from region to region.
  213. /// </param>
  214. /// <param name="opennow">
  215. /// Returns only those places that are open for business at the time the query is sent. \n
  216. /// Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
  217. /// </param>
  218. /// <returns>Query instance to the Google API.</returns>
  219. public static RealWorldTerrainGooglePlaces FindRadar(Vector2 lnglat, int radius, string key, string keyword = null, string name = null, string types = null, int minprice = -1, int maxprice = -1, bool opennow = false)
  220. {
  221. RadarParams p = new RadarParams(lnglat, radius)
  222. {
  223. keyword = keyword,
  224. name = name,
  225. types = types,
  226. };
  227. if (minprice != -1) p.minprice = minprice;
  228. if (maxprice != -1) p.maxprice = maxprice;
  229. if (opennow) p.opennow = true;
  230. return new RealWorldTerrainGooglePlaces(key, p);
  231. }
  232. /// <summary>
  233. /// The Google Places API Radar Search Service allows you to search for up to 200 places at once, but with less detail than is typically returned from a Text Search or Nearby Search request. \n
  234. /// With Radar Search, you can create applications that help users identify specific areas of interest within a geographic area.
  235. /// </summary>
  236. /// <param name="key">
  237. /// Your application's API key. \n
  238. /// This key identifies your application for purposes of quota management and so that places added from your application are made immediately available to your app. \n
  239. /// Visit the Google APIs Console to create an API Project and obtain your key.
  240. /// </param>
  241. /// <param name="p">The object containing the request parameters.</param>
  242. /// <returns>Query instance to the Google API.</returns>
  243. public static RealWorldTerrainGooglePlaces FindRadar(string key, RadarParams p)
  244. {
  245. return new RealWorldTerrainGooglePlaces(key, p);
  246. }
  247. /// <summary>
  248. /// Converts response into an array of results.
  249. /// </summary>
  250. /// <param name="response">Response of Google API.</param>
  251. /// <returns>Array of result.</returns>
  252. public static RealWorldTerrainPlacesResult[] GetResults(string response)
  253. {
  254. string nextPageToken;
  255. return GetResults(response, out nextPageToken);
  256. }
  257. /// <summary>
  258. /// Converts response into an array of results.
  259. /// </summary>
  260. /// <param name="response">Response of Google API.</param>
  261. /// <param name="nextPageToken">
  262. /// Contains a token that can be used to return up to 20 additional results.\n
  263. /// A next_page_token will not be returned if there are no additional results to display.\n
  264. /// The maximum number of results that can be returned is 60.\n
  265. /// There is a short delay between when a next_page_token is issued, and when it will become valid.
  266. /// </param>
  267. /// <returns>Array of result.</returns>
  268. public static RealWorldTerrainPlacesResult[] GetResults(string response, out string nextPageToken)
  269. {
  270. nextPageToken = null;
  271. try
  272. {
  273. RealWorldTerrainXML xml = RealWorldTerrainXML.Load(response);
  274. string status = xml.Find<string>("//status");
  275. if (status != "OK") return null;
  276. nextPageToken = xml.Find<string>("//next_page_token");
  277. RealWorldTerrainXMLList resNodes = xml.FindAll("//result");
  278. List<RealWorldTerrainPlacesResult> results = new List<RealWorldTerrainPlacesResult>(resNodes.count);
  279. foreach (RealWorldTerrainXML node in resNodes) results.Add(new RealWorldTerrainPlacesResult(node));
  280. return results.ToArray();
  281. }
  282. catch (Exception exception)
  283. {
  284. Debug.Log(exception.Message + "\n" + exception.StackTrace);
  285. }
  286. return null;
  287. }
  288. /// <summary>
  289. /// The base class containing the request parameters.
  290. /// </summary>
  291. public abstract class RequestParams
  292. {
  293. public abstract string typePath { get; }
  294. public abstract void AppendParams(StringBuilder url);
  295. }
  296. /// <summary>
  297. /// Request parameters for Nearby Search
  298. /// </summary>
  299. public class NearbyParams : RequestParams
  300. {
  301. /// <summary>
  302. /// The longitude around which to retrieve place information.
  303. /// </summary>
  304. public double? longitude;
  305. /// <summary>
  306. /// The latitude around which to retrieve place information.
  307. /// </summary>
  308. public double? latitude;
  309. /// <summary>
  310. /// Defines the distance (in meters) within which to return place results. \n
  311. /// The maximum allowed radius is 50 000 meters.
  312. /// </summary>
  313. public int? radius;
  314. /// <summary>
  315. /// A term to be matched against all content that Google has indexed for this place, including but not limited to name, type, and address, as well as customer reviews and other third-party content.
  316. /// </summary>
  317. public string keyword;
  318. /// <summary>
  319. /// One or more terms to be matched against the names of places, separated with a space character. \n
  320. /// Results will be restricted to those containing the passed name values. \n
  321. /// Note that a place may have additional names associated with it, beyond its listed name. \n
  322. /// The API will try to match the passed name value against all of these names. \n
  323. /// As a result, places may be returned in the results whose listed names do not match the search term, but whose associated names do.
  324. /// </summary>
  325. public string name;
  326. /// <summary>
  327. /// Restricts the results to places matching at least one of the specified types. \n
  328. /// Types should be separated with a pipe symbol (type1|type2|etc).\n
  329. /// See the list of supported types:\n
  330. /// https://developers.google.com/places/documentation/supported_types
  331. /// </summary>
  332. public string types;
  333. /// <summary>
  334. /// Restricts results to only those places within the specified range. \n
  335. /// Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. \n
  336. /// The exact amount indicated by a specific value will vary from region to region.
  337. /// </summary>
  338. public int? minprice;
  339. /// <summary>
  340. /// Restricts results to only those places within the specified range. \n
  341. /// Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. \n
  342. /// The exact amount indicated by a specific value will vary from region to region.
  343. /// </summary>
  344. public int? maxprice;
  345. /// <summary>
  346. /// Returns only those places that are open for business at the time the query is sent. \n
  347. /// Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
  348. /// </summary>
  349. public bool? opennow;
  350. /// <summary>
  351. /// Specifies the order in which results are listed.
  352. /// </summary>
  353. public RankBy? rankBy;
  354. /// <summary>
  355. /// Returns the next 20 results from a previously run search. \n
  356. /// Setting a pagetoken parameter will execute a search with the same parameters used previously — all parameters other than pagetoken will be ignored.
  357. /// </summary>
  358. public string pagetoken;
  359. /// <summary>
  360. /// Add this parameter (just the parameter name, with no associated value) to restrict your search to locations that are Zagat selected businesses.\n
  361. /// This parameter must not include a true or false value. The zagatselected parameter is experimental, and is only available to Google Places API customers with a Premium Plan license.
  362. /// </summary>
  363. public bool? zagatselected;
  364. /// <summary>
  365. /// The longitude/latitude around which to retrieve place information.
  366. /// </summary>
  367. public Vector2 lnglat
  368. {
  369. get { return new Vector2((float)longitude.Value, (float)latitude.Value); }
  370. set
  371. {
  372. longitude = value.x;
  373. latitude = value.y;
  374. }
  375. }
  376. public override string typePath
  377. {
  378. get { return "nearbysearch"; }
  379. }
  380. /// <summary>
  381. /// Constructor
  382. /// </summary>
  383. /// <param name="longitude">The longitude around which to retrieve place information.</param>
  384. /// <param name="latitude">The latitude around which to retrieve place information.</param>
  385. /// <param name="radius">
  386. /// Defines the distance (in meters) within which to return place results. \n
  387. /// The maximum allowed radius is 50 000 meters.
  388. /// </param>
  389. public NearbyParams(double longitude, double latitude, int radius)
  390. {
  391. this.longitude = longitude;
  392. this.latitude = latitude;
  393. this.radius = radius;
  394. }
  395. /// <summary>
  396. /// Constructor
  397. /// </summary>
  398. /// <param name="lnglat">The longitude/latitude around which to retrieve place information.</param>
  399. /// <param name="radius">
  400. /// Defines the distance (in meters) within which to return place results. \n
  401. /// The maximum allowed radius is 50 000 meters.
  402. /// </param>
  403. public NearbyParams(Vector2 lnglat, int radius)
  404. {
  405. this.lnglat = lnglat;
  406. this.radius = radius;
  407. }
  408. /// <summary>
  409. /// Constructor
  410. /// </summary>
  411. /// <param name="pagetoken">
  412. /// Returns the next 20 results from a previously run search. \n
  413. /// Setting a pagetoken parameter will execute a search with the same parameters used previously — all parameters other than pagetoken will be ignored.
  414. /// </param>
  415. public NearbyParams(string pagetoken)
  416. {
  417. this.pagetoken = pagetoken;
  418. }
  419. public override void AppendParams(StringBuilder url)
  420. {
  421. if (latitude.HasValue && longitude.HasValue) url.Append("&location=").Append(latitude.Value).Append(",").Append(longitude.Value);
  422. if (radius.HasValue) url.Append("&radius=").Append(radius.Value);
  423. if (!string.IsNullOrEmpty(keyword)) url.Append("&keyword=").Append(keyword);
  424. if (!string.IsNullOrEmpty(name)) url.Append("&name=").Append(name);
  425. if (!string.IsNullOrEmpty(types)) url.Append("&types=").Append(types);
  426. if (minprice.HasValue) url.Append("&minprice=").Append(minprice.Value);
  427. if (maxprice.HasValue) url.Append("&maxprice=").Append(maxprice.Value);
  428. if (opennow.HasValue) url.Append("&opennow");
  429. if (rankBy.HasValue) url.Append("&rankby=").Append(rankBy.Value);
  430. if (!string.IsNullOrEmpty(pagetoken)) url.Append("&pagetoken=").Append(RealWorldTerrainWWW.EscapeURL(pagetoken));
  431. if (zagatselected.HasValue && zagatselected.Value) url.Append("&zagatselected");
  432. }
  433. }
  434. /// <summary>
  435. /// Request parameters for Text Search
  436. /// </summary>
  437. public class TextParams : RequestParams
  438. {
  439. /// <summary>
  440. /// The text string on which to search, for example: "restaurant". \n
  441. /// The Google Places service will return candidate matches based on this string and order the results based on their perceived relevance.
  442. /// </summary>
  443. public string query;
  444. /// <summary>
  445. /// The longitude around which to retrieve place information.
  446. /// </summary>
  447. public double? longitude;
  448. /// <summary>
  449. /// The latitude around which to retrieve place information.
  450. /// </summary>
  451. public double? latitude;
  452. /// <summary>
  453. /// Defines the distance (in meters) within which to bias place results. \n
  454. /// The maximum allowed radius is 50 000 meters. \n
  455. /// Results inside of this region will be ranked higher than results outside of the search circle; however, prominent results from outside of the search radius may be included.
  456. /// </summary>
  457. public int? radius;
  458. /// <summary>
  459. /// The language code, indicating in which language the results should be returned, if possible.
  460. /// </summary>
  461. public string language;
  462. /// <summary>
  463. /// Restricts the results to places matching at least one of the specified types. \n
  464. /// Types should be separated with a pipe symbol (type1|type2|etc). \n
  465. /// See the list of supported types:\n
  466. /// https://developers.google.com/maps/documentation/places/supported_types
  467. /// </summary>
  468. public string types;
  469. /// <summary>
  470. /// Restricts results to only those places within the specified price level. \n
  471. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  472. /// The exact amount indicated by a specific value will vary from region to region.
  473. /// </summary>
  474. public int? minprice;
  475. /// <summary>
  476. /// Restricts results to only those places within the specified price level. \n
  477. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  478. /// The exact amount indicated by a specific value will vary from region to region.
  479. /// </summary>
  480. public int? maxprice;
  481. /// <summary>
  482. /// Returns only those places that are open for business at the time the query is sent. \n
  483. /// Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
  484. /// </summary>
  485. public bool? opennow;
  486. /// <summary>
  487. /// Returns the next 20 results from a previously run search. \n
  488. /// Setting a pagetoken parameter will execute a search with the same parameters used previously — all parameters other than pagetoken will be ignored.
  489. /// </summary>
  490. public string pagetoken;
  491. /// <summary>
  492. /// Add this parameter (just the parameter name, with no associated value) to restrict your search to locations that are Zagat selected businesses.\n
  493. /// This parameter must not include a true or false value. The zagatselected parameter is experimental, and is only available to Google Places API customers with a Premium Plan license.
  494. /// </summary>
  495. public bool? zagatselected;
  496. /// <summary>
  497. /// The longitude/latitude around which to retrieve place information.
  498. /// </summary>
  499. public Vector2 lnglat
  500. {
  501. get { return new Vector2((float)longitude.Value, (float)latitude.Value); }
  502. set
  503. {
  504. longitude = value.x;
  505. latitude = value.y;
  506. }
  507. }
  508. public override string typePath
  509. {
  510. get { return "textsearch"; }
  511. }
  512. /// <summary>
  513. /// Contstructor
  514. /// </summary>
  515. /// <param name="query">
  516. /// The text string on which to search, for example: "restaurant". \n
  517. /// The Google Places service will return candidate matches based on this string and order the results based on their perceived relevance.
  518. /// </param>
  519. public TextParams(string query)
  520. {
  521. this.query = query;
  522. }
  523. public override void AppendParams(StringBuilder url)
  524. {
  525. if (latitude.HasValue && longitude.HasValue) url.Append("&location=").Append(latitude.Value).Append(",").Append(longitude.Value);
  526. if (radius.HasValue) url.Append("&radius=").Append(radius.Value);
  527. if (!string.IsNullOrEmpty(types)) url.Append("&types=").Append(types);
  528. if (!string.IsNullOrEmpty(query)) url.Append("&query=").Append(RealWorldTerrainWWW.EscapeURL(query));
  529. if (!string.IsNullOrEmpty(language)) url.Append("&language=").Append(language);
  530. if (minprice.HasValue) url.Append("&minprice=").Append(minprice.Value);
  531. if (maxprice.HasValue) url.Append("&maxprice=").Append(maxprice.Value);
  532. if (opennow.HasValue && opennow.Value) url.Append("&opennow");
  533. if (!string.IsNullOrEmpty(pagetoken)) url.Append("&pagetoken=").Append(pagetoken);
  534. if (zagatselected.HasValue && zagatselected.Value) url.Append("&zagatselected");
  535. }
  536. }
  537. /// <summary>
  538. /// Request parameters for Radar Search
  539. /// </summary>
  540. public class RadarParams : RequestParams
  541. {
  542. /// <summary>
  543. /// The longitude around which to retrieve place information.
  544. /// </summary>
  545. public double? longitude;
  546. /// <summary>
  547. /// The latitude around which to retrieve place information.
  548. /// </summary>
  549. public double? latitude;
  550. /// <summary>
  551. /// Defines the distance (in meters) within which to return place results. \n
  552. /// The maximum allowed radius is 50 000 meters.
  553. /// </summary>
  554. public int? radius;
  555. /// <summary>
  556. /// A term to be matched against all content that Google has indexed for this place, including but not limited to name, type, and address, as well as customer reviews and other third-party content.
  557. /// </summary>
  558. public string keyword;
  559. /// <summary>
  560. /// One or more terms to be matched against the names of places, separated by a space character. \n
  561. /// Results will be restricted to those containing the passed name values. \n
  562. /// Note that a place may have additional names associated with it, beyond its listed name. \n
  563. /// The API will try to match the passed name value against all of these names. \n
  564. /// As a result, places may be returned in the results whose listed names do not match the search term, but whose associated names do.
  565. /// </summary>
  566. public string name;
  567. /// <summary>
  568. /// Restricts the results to places matching at least one of the specified types. \n
  569. /// Types should be separated with a pipe symbol (type1|type2|etc). \n
  570. /// See the list of supported types:\n
  571. /// https://developers.google.com/maps/documentation/places/supported_types
  572. /// </summary>
  573. public string types;
  574. /// <summary>
  575. /// Restricts results to only those places within the specified price level. \n
  576. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  577. /// The exact amount indicated by a specific value will vary from region to region.
  578. /// </summary>
  579. public int? minprice;
  580. /// <summary>
  581. /// Restricts results to only those places within the specified price level. \n
  582. /// Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. \n
  583. /// The exact amount indicated by a specific value will vary from region to region.
  584. /// </summary>
  585. public int? maxprice;
  586. /// <summary>
  587. /// Returns only those places that are open for business at the time the query is sent. \n
  588. /// Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
  589. /// </summary>
  590. public bool? opennow;
  591. /// <summary>
  592. /// Add this parameter (just the parameter name, with no associated value) to restrict your search to locations that are Zagat selected businesses.\n
  593. /// This parameter must not include a true or false value. The zagatselected parameter is experimental, and is only available to Google Places API customers with a Premium Plan license.
  594. /// </summary>
  595. public bool? zagatselected;
  596. /// <summary>
  597. /// The longitude/latitude around which to retrieve place information.
  598. /// </summary>
  599. public Vector2 lnglat
  600. {
  601. get { return new Vector2((float)longitude.Value, (float)latitude.Value); }
  602. set
  603. {
  604. longitude = value.x;
  605. latitude = value.y;
  606. }
  607. }
  608. public override string typePath
  609. {
  610. get { return "radarsearch"; }
  611. }
  612. /// <summary>
  613. /// Constructor
  614. /// </summary>
  615. /// <param name="longitude">The longitude around which to retrieve place information.</param>
  616. /// <param name="latitude">The latitude around which to retrieve place information.</param>
  617. /// <param name="radius">
  618. /// Defines the distance (in meters) within which to return place results. \n
  619. /// The maximum allowed radius is 50 000 meters.
  620. /// </param>
  621. public RadarParams(double longitude, double latitude, int radius)
  622. {
  623. this.longitude = longitude;
  624. this.latitude = latitude;
  625. this.radius = radius;
  626. }
  627. /// <summary>
  628. /// Constructor
  629. /// </summary>
  630. /// <param name="lnglat">The longitude/latitude around which to retrieve place information.</param>
  631. /// <param name="radius">
  632. /// Defines the distance (in meters) within which to return place results. \n
  633. /// The maximum allowed radius is 50 000 meters.
  634. /// </param>
  635. public RadarParams(Vector2 lnglat, int radius)
  636. {
  637. this.lnglat = lnglat;
  638. this.radius = radius;
  639. }
  640. public override void AppendParams(StringBuilder url)
  641. {
  642. if (latitude.HasValue && longitude.HasValue) url.Append("&location=").Append(latitude.Value).Append(",").Append(longitude.Value);
  643. if (radius.HasValue) url.Append("&radius=").Append(radius.Value);
  644. if (!string.IsNullOrEmpty(keyword)) url.Append("&keyword=").Append(keyword);
  645. if (!string.IsNullOrEmpty(name)) url.Append("&name=").Append(name);
  646. if (!string.IsNullOrEmpty(types)) url.Append("&types=").Append(types);
  647. if (minprice.HasValue) url.Append("&minprice=").Append(minprice.Value);
  648. if (maxprice.HasValue) url.Append("&maxprice=").Append(maxprice.Value);
  649. if (opennow.HasValue && opennow.Value) url.Append("&opennow");
  650. if (zagatselected.HasValue && zagatselected.Value) url.Append("&zagatselected");
  651. }
  652. }
  653. /// <summary>
  654. /// Specifies the order in which results are listed.
  655. /// </summary>
  656. public enum RankBy
  657. {
  658. /// <summary>
  659. /// This option sorts results based on their importance. \n
  660. /// Ranking will favor prominent places within the specified area. \n
  661. /// Prominence can be affected by a place's ranking in Google's index, global popularity, and other factors.
  662. /// </summary>
  663. prominence,
  664. /// <summary>
  665. /// This option sorts results in ascending order by their distance from the specified location. \n
  666. /// When distance is specified, one or more of keyword, name, or types is required.
  667. /// </summary>
  668. distance
  669. }
  670. }
  671. }