location_API.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. This file describes the public API for the CivicSpace location system as defined by
  2. in the library implemented by "location.inc" and its supporting files.
  3. For a example of this API's usage, please consult "location.module"
  4. FUNCTION SPECIFICATIONS DESCRIBED IN THIS FILE:
  5. ----------------------------------------------
  6. location_get_postalcode_data(): A function that takes a (postalcode,country) pair an returns lat/lon, city, province. This
  7. function is meant to replace location_latlon_rough(); see below.
  8. location_latlon_rough(): A function that returns the latitude and longitude of the specified postal-code/country pair.
  9. This latitude and longitude will be of the approximate center of the postal-code's area. This function
  10. will soon be removed from the API as it has been replaced by the more comprehensive
  11. location_get_postalcode_data() described above. [TO BE DEPRECATED]
  12. location_latlon_exact(): A function that returns the latitude and longitude of the given full location. Typically implemented
  13. on top of a web-service. [TO BE IMPLEMENTED]
  14. location_map_link(): A function that returns, based on the site configuration, either NULL or 1 or more deep-links to mapping
  15. web sites for the parameter location array.
  16. location_driving_directions_link(): A function that returns, given 2 locationes, a deep-link to Yahoo! Maps or some other site
  17. that provides driving directions. The site chosen depends on the implementation at the country-level.
  18. location_proximity_form(): A function that generates a form for collecting proximity search parameters.
  19. location_valid(): A function for validating locationes. [TO BE SPECIFIED]
  20. theme_location(): A function that takes in an location and themes it. (e.g., $output .= theme('location', $location)).
  21. location_distance_between(): A function that, given a pair of lat/lon pairs, returns the distance between them.
  22. "[TO BE SPECIFIED]" => Function spec has not been completed and may possibly be eliminated from spec.
  23. "[TO BE IMPLEMENTED]" => Function spec exists but is to be implemented in a future release.
  24. "[TO BE DEPRECATED]" => This function will soon be removed from the API.
  25. ----------------------------------------------
  26. IMPORTANT NOTES:
  27. ----------------
  28. Formats
  29. ---
  30. In the following API, a 'location' is merely an associative array with the following keys:
  31. 'street' => A string for the street portion of an location
  32. 'additional' => A string for the additional street portion of an location
  33. 'province' => An upper-case, standard postal abbreviation of a state/province/territory
  34. 'postal_code' => A string or integer for the postal code
  35. 'country' => The lower-case of the ISO 3166 two-letter alpha code (e.g., 'us' for U.S., 'ca' for Canada).
  36. For locations that are passed to location_form() for the $prefilled_values parameter, the same format applies
  37. except that the 'province' field is the concatenation of the country code, '-', and the province abbreviation.
  38. For example, 'CA' is the value for California for all purposes, but when passing this in a location for prefilled
  39. values, it should be 'us-CA'. There are two functions to help convert back and forth between these formats:
  40. location_form2api() and location_api2form(). These are described further below.
  41. Delegation
  42. ---
  43. With the exception of location_form() and location_proximity_form(), the calls to functions listed here are, in the end,
  44. dispatched to country-specific location libraries which are implemented in country-specific '.inc' files. For example,
  45. location_latlon_rough(), when given a U.S. location, really returns a result that is determined by call to
  46. "location_latlon_rough_us()" which is implemented in the file "location.us.inc".
  47. Current Implementation
  48. ---
  49. Currently, the only country supported is the United States. For the future, however, there will be documentation for how to
  50. implement a country-specific include file that can be plugged into the system to support these calls for new countries. This
  51. scheme will revolve around method signatures for a handful of simple-to-write functions.
  52. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  53. function location_get_postalcode_data($location = array()); +
  54. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  55. Takes a location and uses the combination of postal code and country to return an array that gives the
  56. city, province, and lat/lon dat for that postal code.
  57. @param $location
  58. An associative array $location where
  59. 'street' => the street portion of the location
  60. 'additional' => additional street portion of the location
  61. 'province' => the province, state, or territory
  62. 'country' => lower-cased two-letter ISO code (REQUIRED)
  63. 'postal_code' => international postal code (REQUIRED)
  64. @return
  65. NULL if data cannot be found.
  66. Otherwise, an associative array where
  67. 'lat' => is a floating point of the latitude coordinate of this location
  68. 'lon' => is a floating point of the longitude coordinate of this location
  69. 'city' => is a string for the city this postalcode is in (or the most recognized city at the given postal)
  70. 'province' => the province of the given postal code.
  71. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  72. function location_latlon_rough($location = array()); +
  73. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  74. Takes an location and returns a "rough" latitude/longitude pair based on the postal code
  75. data available for the given country.
  76. @param $location
  77. An associative array $location where
  78. 'street' => the street portion of the location
  79. 'additional' => additional street portion of the location
  80. 'province' => the province, state, or territory
  81. 'country' => lower-cased two-letter ISO code (REQUIRED)
  82. 'postal_code' => international postal code (REQUIRED)
  83. @return
  84. NULL if data cannont be found.
  85. Otherwise, an associative array where
  86. 'lat' => is a floating point of the latitude coordinate of this location
  87. 'lon' => is a floating point of the longitude coordinate of this location
  88. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  89. function location_latlon_exact($location = array()); +
  90. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  91. Currently, this is not a priority until there is an implementable use for exact longitude,
  92. latitude coordinates for an location. The idea is that this call will eventually retrieve
  93. information through a web-service. Whereas location_latlon_rough() returns an approximate
  94. lat/lon pair based strictly on the postal code where this lat/lon pair is pulled from a
  95. database table, this function is intended to send the entire location to a web-service and
  96. to retrieve exact lat/lon coordinates.
  97. @param $location
  98. An array where
  99. -> the key values are 'street', 'additional', 'province', 'country', 'postal_code'
  100. -> the values are:
  101. 'street' => the string representing the street location (REQUIRED)
  102. 'additional' => the string representing the additional street location portion in the location form
  103. 'city' => the city name (REQUIRED)
  104. 'province' => the province code defined in the country-specific include file
  105. 'country' => the lower-case of the two-letter ISO code (REQUIRED)
  106. 'postal_code' => the postal-code (REQUIRED)
  107. @return
  108. NULL if the delegated-to function that does the actual look-up does not exist.
  109. If the appropriate function exists, then this function returns an associative array where
  110. 'lon' => A floating point number for the longitude coordinate of the parameter location
  111. 'lat' => A floating point number for the latitude coordinate of the parameter location
  112. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  113. function location_map_link($location = array(), $link_text = 'See map'); +
  114. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  115. Get deep-links to a mapping services such as Yahoo! Maps or MapQuest (actual providers depend on configuration
  116. of location module) given a location. The call is delegated based on the 'country' value in the $location parameter.
  117. @param $location
  118. An associative array where
  119. 'street' => A string representing the street location
  120. 'additional' => A string for any additional portion of the street location
  121. 'city' => A string for the city name
  122. 'province' => The standard postal abbreviation for the province
  123. 'country' => The two-letter ISO code for the country of the location (REQUIRED)
  124. 'postal_code' => The international postal code for the location
  125. @return
  126. NULL if there are not mapping providers configured for the country or if no links could be generated.
  127. A string of the form "See map: Yahoo! Maps, MapQuest" where Yahoo! Maps and Mapquest are links to the
  128. given location and can be replaced with other options (e.g., Google) available in the location module settings.
  129. The idea is to encode the appropriate parameters as HTTP GET variables to the URL.
  130. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  131. function location_driving_directions_link($locationA = array(), $locationB = array(), $link_text = 'Get directions');
  132. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  133. Takes two locationes and tries to return a deep-link to driving directions.
  134. Parameters:
  135. @param $locationA
  136. An associative array that represents an location where
  137. 'street' => the street portions of the location
  138. 'additional' => additional street portion of the location
  139. 'city' => the city name
  140. 'province' => the province, state, or territory
  141. 'country' => lower-cased two-letter ISO code (REQUIRED)
  142. 'postal_code' => the postal code
  143. @param $locationB
  144. An associative array that represents an location in the same way that
  145. parameter $locationA does.
  146. @param $link_text
  147. The text of the HTML link that is to be generated.
  148. @return
  149. A deep-link to driving directions on Yahoo! or some other mapping service, if enough fields are filled in the parameters.
  150. A deep-link to a form for driving directions with information pre-filled if not enough, but some fields are filled in the parameters.
  151. The empty string if no information is provided (or if so little information is provided that there is no function to which to delegate
  152. the call.
  153. We dispatch the call to a country-specific function. The country-specific function, in this case,
  154. will be the one reflected by the country parameter of the first function. We require that
  155. both locationes supplied have a country field at the minimum.
  156. The country-specific functions will ultimately decide, with the parameters given, whether to
  157. to link to a form for driving directions is provided, where this form will be
  158. pre-populated with whatever values were available or whether to link directly to the driving
  159. directions themselves if enough fields are filled for each location.
  160. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  161. function location_proximity_form($location_form = '', $label = '', $description = '', $prefilled_values = array(), $form_name = 'location');
  162. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  163. This function generates a form for doing proximity searches within a certain distance
  164. of a specified point.
  165. Depending on the context within which this function is called, the search-point can either
  166. be user-supplied via the location form that is passed (if one is available) or done within
  167. a search-point extracted from a contact table or some other location source specified by
  168. the programmer calling this function.
  169. @param $location_form
  170. An optional location form, preferably generated by location_form(). If the script processing this
  171. form also needs a user-supplied location, this parameter is used to specify a form for collecting the
  172. search-point about which this search is being done. If the caller does not supply a form, it is
  173. assumed that the caller already has a search point in mind and that this will be made clear in
  174. the $description parameter.
  175. @param $label
  176. The label you want to apply to the form group that is returned (passed as $legend param to form_group()).
  177. @param $description
  178. A text description of what is being searched for (e.g., 'Find all upcoming events near you.')
  179. @param $prefilled_values
  180. An associative array for prefilled values for the proximity search parameters, where
  181. 'distance' => is the prefilled int value to be selected for the distance scalar
  182. 'distance_unit' => is 'km' or 'mile'
  183. @param $form_name
  184. An additional parameter to help prevent HTML input name collisions. If the caller is using this
  185. function to generate more than 1 location proximity form on a page, then the generated name for
  186. each HTML input's "name" attribute will be $form_name. Allowing the caller to pass $form_name allows
  187. the caller the flexibility of using more than one location proximity search form on one page.
  188. @return
  189. An HTML form (generated by Drupal form functions) that lets users specify proximity search parameters that include distance,
  190. the unit of distance, and a search-point if the optional $location_form parameter is passed. If one is not passed,
  191. the caller of this function will be assumed to already have one.
  192. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  193. function theme_location($location = array()); +
  194. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  195. Generates HTML for the passed location.
  196. @param $location
  197. An associative array where
  198. 'street' => A string representing the street location
  199. 'additional' => A string for any additional portion of the street location
  200. 'city' => A string for the city name
  201. 'province' => The standard postal abbreviation for the province
  202. 'country' => The two-letter ISO code for the country of the location (REQUIRED)
  203. 'postal_code' => The international postal code for the location
  204. @return
  205. An HTML string with special tags for locationes.
  206. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  207. function location_distance_between($latlonA = array(), $latlonB = array(), $distance_unit = 'km'); +
  208. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  209. Given two points in lat/lon form, returns the distance between them.
  210. @param $latlonA
  211. An associative array where
  212. 'lon' => is a floating point of the longitude coordinate for the point given by latlonA
  213. 'lat' => is a floating point of the latitude coordinate for the point given by latlonB
  214. @param $latlonB
  215. Another point formatted like $latlonB
  216. @param $distance_unit
  217. A string that is either 'km' or 'mile'.
  218. If neither 'km' or 'mile' is passed, the parameter is forced to 'km'
  219. @return
  220. NULL if sense can't be made of the parameters.
  221. An associative array where
  222. 'scalar' => Is the distance between the two lat/lon parameter points
  223. 'distance_unit' => Is the unit of distance being represented by 'scalar'.
  224. This will be 'km' unless 'mile' is passed for the $distance_unit param