extending.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <p><em>Note:</em> This file describes the original country API. While the API itself hasn't
  2. changed, some things have moved in directions not forseen by this documentation.
  3. For example, there is less emphasis today on postal data and more emphasis on
  4. geocoding webservices. Please take this documentation with a grain of salt until
  5. it is fully cleaned up and brought up to date.</p>
  6. <h3>location.xx.inc: Adding support for an unsupported country</h3>
  7. <hr />
  8. <p>This file is a PHP programmer's description of what needs to be done in order to extend the
  9. location system to support locationes from a new country.</p>
  10. <p>Let's suppose we want to extend the location system to support locationes from Belgium. To this end,
  11. there are 2 tasks:</p>
  12. TASK #1
  13. <p>We use the lower-case of the country's two-letter ISO 3166 code to create a file, "location.be.inc", that
  14. defines the necessary functions that will "hook" into the location system. This way, when a high-level
  15. function in the public location API receives a call that uses some Belgium specific function, the call
  16. will be delegated to the appropriately named function in "location.be.inc".</p>
  17. TASK #2
  18. <p>You need postal code data for your country. This postal code data needs to be able to connect the
  19. base-length postal code (e.g., U.S. postal codes can be 9 digits, but we're only interested to the
  20. level of 5 digits and most people only know the 5-digit version) to a city, province/state, country (duh),
  21. and a latitude/longitude pair in degrees that represents the approximate center of the postal code's area.
  22. Ultimately, you will want to create a database dump that inserts these fields into specific columns:
  23. 'zip' (for postal codes), 'city' (for city names), 'province' for (the standard state/province/country
  24. abbreviation), 'country' (for the lower-case of the country's two letter ISO code), 'latitude' (for the
  25. latitude in degree value, as opposed to radian value) and 'longitude' (for the degree value of the
  26. longitude).</p>
  27. <p>In a lot of countries, this data costs money! You cannot simply create a dump and then publish it on
  28. drupal.org unless the data is free to redistribute. However, if you are interested in buying this data
  29. from some vendor and using it on your own site, you can do so but may have to acquire a new license for
  30. each seperate business or web site for which you wish to use postal code data if, in fact, you had to
  31. pay a fee or license for this data.</p>
  32. <p>This postalcode-to-lat/lon mapping is important if you want to enable location-based proximity searches of
  33. anykind for addresses in a particular country. The module will still work fine without it, but will not
  34. be able to support searches based on postal codes.</p>
  35. <h3>Contents of location.be.inc</h3>
  36. <hr />
  37. <p>This file will need to implement a handful of functions with the parameters and return values described below.</p>
  38. <p>It is possible to not implement all of these functions since the caller usually checks to see if the function
  39. exists before calling it, but it may limit the number of features the location system will be able to support
  40. for your country.</p>
  41. <p>For an example implementation of the functions described below, see "supported/location.us.inc".</p>
  42. <pre>
  43. -------------------------------------------------------------------------------------------------
  44. function theme_location_be($location, $hide); |
  45. -------------------------------------------------------------------------------------------------
  46. @param $location
  47. An associative array $location where
  48. 'street' => the street portion of the location
  49. 'additional' => additional street portion of the location
  50. 'city' => the city of the location
  51. 'province' => the province, state, or territory
  52. 'country' => lower-cased two-letter ISO code (REQUIRED)
  53. 'postal_code' => the international postal code for this location (REQUIRED)
  54. @param $hide
  55. An linear array where the values are the location fields to suppress in the themed display.
  56. @return
  57. A string of the themed location. The entire location should be enclosed by &lt;dl class="location"&gt; &lt;/dl&gt; tags.
  58. The different lines of the location should be enclosed by &lt;dl&gt; &lt;/dl&gt; tags. The idea is to allow country-specific
  59. files to change the display of an location from the default theming done in theme_location() defined in location.inc
  60. </pre>
  61. <pre>
  62. -------------------------------------------------------------------------------------------------
  63. function location_province_list_be(); |
  64. -------------------------------------------------------------------------------------------------
  65. Returns an associative array where
  66. -> the keys are the all-uppercase standard postal abbreviation for provinces, territories, and like subdivisions.
  67. -> the values are the fully spelled names of the abbreviated names.
  68. Preferrably, these will be sorted by the full name.
  69. </pre>
  70. <pre>
  71. -------------------------------------------------------------------------------------------------
  72. function location_map_link_be($location); |
  73. -------------------------------------------------------------------------------------------------
  74. Returns a deep-link to an online mapping service (e.g., "Yahoo! Maps", "MapQuest", or some other
  75. preferrably free service) given a full/partial location in the format described in public API
  76. document (location_API.txt).
  77. @param $location
  78. An associative array $location where
  79. 'street' => the street portion of the location
  80. 'additional' => additional street portion of the location
  81. 'city' => the city of the location
  82. 'province' => the province, state, or territory
  83. 'country' => lower-cased two-letter ISO code (REQUIRED)
  84. 'postal_code' => the international postal code for this location (REQUIRED)
  85. @return
  86. A URL with encoded HTTP GET variables to a free online-mapping service. (Note: URL, not HTML link).
  87. NULL if there is not even enough information to generate even a semi-useful link. "Useful" may depend
  88. entirely on the mapping service you choose to link to. You are advised to experiment: usually, a
  89. city/province combination is enough as is a postal code by itself, however, some services get confused
  90. when all fields are supplied. Some mapping services will be unable to map a city/province location
  91. while they can't do anything with a postal code while others map postal codes fine, but can't do
  92. anything useful with a city/province pair.
  93. </pre>
  94. <pre>
  95. --------------------------------------------------------------------------------------------------
  96. function location_map_link_be_providers(); |
  97. --------------------------------------------------------------------------------------------------
  98. Returns an array of mapping services to which the generation of deep-links is supported. "Supported"
  99. means that the function for that particular mapping service has been defined. For example, if the
  100. location.be.inc file for Belgium has functions for taking a location and generating a deep-link to
  101. Yahoo! Maps and google, this function will return that list in an array that give additional info.
  102. See location.us.inc for an example.
  103. @return
  104. An associative array where
  105. --> The keys are single words (no spaces) that identify a function in the same file for returning
  106. a deep link. For example, 'yahoo' means location_map_link_be_yahoo(). 'google' means
  107. location_map_link_be_google().
  108. --> The values are themselves associative arrays with 3 expected keys:
  109. 'name' => The name of the mapping service. In the case of Yahoo, it would be 'Yahoo! Maps'
  110. 'url' => The full URL of the main page of the mapping service (i.e., the home page)
  111. 'tos' => The full URL of the Terms Of Service for the mapping service.
  112. </pre>
  113. <pre>
  114. --------------------------------------------------------------------------------------------------
  115. function location_map_link_be_default_providers(); |
  116. --------------------------------------------------------------------------------------------------
  117. Returns an array of 'default' mapping services. It may happen that the site administrator has not
  118. yet made it to the settings page for selecting mapping providers. In this case, we want to tell
  119. the location modules which one to use as defaults. To help the site admin avoid being in violation
  120. of each mapping services's Terms of Service, we return a linear array whose values are the appropriately
  121. selected keys in the array returned the location_map_link_xx_providers() function.
  122. @return
  123. A linear array with the one-word, no-spaced identifiers used to identify the mapping function. These
  124. should only be for the mapping services with relatively lenient and permissive Terms of Service.
  125. IMPORTANT: For more information on how to add support for deep-links, you are encouraged to see
  126. the examples in modules/location/supported/location.us.inc. If you need extra help, please feel
  127. free to submit a question on the issues queue for this project at: http://drupal.org/project/issues/location
  128. Replies will be prompt.
  129. </pre>
  130. <pre>
  131. --------------------------------------------------------------------------------------------------
  132. function location_driving_directions_link_be($locationA, $locationB); |
  133. --------------------------------------------------------------------------------------------------
  134. Returns a deep-link to an online mapping service (e.g., "Yahoo! Maps", "MapQuest", or some other
  135. preferrably free service) given full/partial locationes. Depending on whether or not the parameter
  136. locationes are complete enough for the chosen service, this function will return either a deep-link
  137. directly to the driving direction or will provide a deep-link to a partially pre-filled form for
  138. driving directions on the site you choose to link to.
  139. @param $locationA
  140. An associative array $location where
  141. 'street' => the street portion of the location
  142. 'additional' => additional street portion of the location
  143. 'city' => the city of the location
  144. 'province' => the province, state, or territory
  145. 'country' => lower-cased two-letter ISO code (REQUIRED)
  146. 'postal_code' => the international postal code for this location (REQUIRED)
  147. @param $locationB
  148. An associative array $location where
  149. 'street' => the street portion of the location
  150. 'additional' => additional street portion of the location
  151. 'city' => the city of the location
  152. 'province' => the province, state, or territory
  153. 'country' => lower-cased two-letter ISO code (REQUIRED)
  154. 'postal_code' => the international postal code for this location (REQUIRED)
  155. @return
  156. A URL (not HTML link) with HTTP GET variables tacked on to the end. This URL either points to a
  157. form for driving directions from $locationA to $locationB or a deep-link directly to the driving
  158. directions depending on how complete the locationes are.
  159. </pre>
  160. <pre>
  161. --------------------------------------------------------------------------------------------------
  162. function location_get_postalcode_data_be($location = array()); |
  163. --------------------------------------------------------------------------------------------------
  164. @param $location
  165. An associative array $location where
  166. 'street' => the street portion of the location
  167. 'additional' => additional street portion of the location
  168. 'city' => the city of the location
  169. 'province' => the province, state, or territory
  170. 'country' => lower-cased two-letter ISO code (REQUIRED)
  171. 'postal_code' => the international postal code for this location (REQUIRED)
  172. @return
  173. An associative array where
  174. 'lat' => A floating point for the latitude of the approximate center of the postal_code in the given $location
  175. 'lon' => A floating point for the longitude of the approximate center of the postal code in the given $location
  176. 'city' => The most appropriate city name for the given postal code in $location
  177. 'province' => The most appropriate province name for the given postal code in $location
  178. Returns NULL if the postal code doesn't make sense.
  179. Typically, this function will pull out the latitude/longitude of the approximate center of postal code
  180. in the given $location parameter as well as other data. The reason this can't be implemented at the
  181. non-country specific level in location.inc is that postal codes may be submitted in varying formats
  182. of varying precision while postal codes for this country in the database table may all be in a particular
  183. format. It is up to this country specific function to examine $location['postal_code'] and format it
  184. appropriately so that it matches with a postal code in the postal codes table. This 'hook' is meant
  185. to be a replacement for the location_get_latlon_rough_xx hook, described next.
  186. </pre>
  187. <pre>
  188. --------------------------------------------------------------------------------------------------
  189. function location_latlon_rough_be($location = array()); |
  190. --------------------------------------------------------------------------------------------------
  191. @param $location
  192. An associative array $location where
  193. 'street' => the street portion of the location
  194. 'additional' => additional street portion of the location
  195. 'city' => the city of the location
  196. 'province' => the province, state, or territory
  197. 'country' => lower-cased two-letter ISO code (REQUIRED)
  198. 'postal_code' => the international postal code for this location (REQUIRED)
  199. @return
  200. An associative array where
  201. 'lat' => A floating point for the latitude of the approximate center of the postal_code in the given $location
  202. 'lon' => A floating point for the longitude of the approximate center of the postal code in the given $location
  203. Returns NULL if the postal code doesn't make sense.
  204. Typically, this function will pull out the latitude/longitude of the approximate center of postal code
  205. in the given $location parameter.
  206. </pre>
  207. <pre>
  208. --------------------------------------------------------------------------------------------------
  209. function location_latlon_exact_be($location = array()); |
  210. --------------------------------------------------------------------------------------------------
  211. @param $location
  212. An associative array $location where
  213. 'street' => the street portion of the location
  214. 'additional' => additional street portion of the location
  215. 'city' => the city of the location
  216. 'province' => the province, state, or territory
  217. 'country' => lower-cased two-letter ISO code (REQUIRED)
  218. 'postal_code' => the international postal code for this location (REQUIRED)
  219. @return
  220. An associative array where
  221. 'lat' => A floating point for the latitude of the approximate center of the postal_code in the given $location
  222. 'lon' => A floating point for the longitude of the approximate center of the postal code in the given $location
  223. Returns NULL if the postal code doesn't make sense.
  224. Typically, this function will be implemented on top of a web-service for retrieving exact lat/lon information
  225. for a full location. This function is not a necessity, but a sample implementation would be helpful for
  226. future users. If not, it can always be added on a supply and demand basis.
  227. </pre>