location.ch.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // Switzerland
  3. function location_province_list_ch() {
  4. return array(
  5. 'ZH' => "Zurich",
  6. 'BE' => "Bern",
  7. 'LU' => "Lucerne",
  8. 'UR' => "Uri",
  9. 'SZ' => "Schwyz",
  10. 'OW' => "Obwalden",
  11. 'NW' => "Nidwalden",
  12. 'GL' => "Glarus",
  13. 'ZG' => "Zug",
  14. 'FR' => "Fribourg",
  15. 'SO' => "Solothurn",
  16. 'BS' => "Basel-Stadt",
  17. 'BL' => "Basel-Landschaft",
  18. 'SH' => "Schaffhausen",
  19. 'AR' => "Appenzell Ausserrhoden",
  20. 'AI' => "Appenzell Innerhoden",
  21. 'SG' => "St. Gallen",
  22. 'GR' => "Graubunden",
  23. 'AG' => "Aargau",
  24. 'TG' => "Thurgau",
  25. 'TI' => "Ticino",
  26. 'VD' => "Vaud",
  27. 'VS' => "Valais",
  28. 'NE' => "Neuchatel",
  29. 'GE' => "Geneva",
  30. 'JU' => "Jura",
  31. );
  32. }
  33. function location_map_link_ch_providers() {
  34. return array(
  35. 'search' => array(
  36. 'name' => 'map.search.ch',
  37. 'url' => 'http://map.search.ch',
  38. 'tos' => 'http://map.search.ch/terms.html',
  39. ),
  40. 'google' => array(
  41. 'name' => 'Google Maps',
  42. 'url' => 'http://maps.google.ch',
  43. 'tos' => 'http://www.google.ch/help/terms_maps.html',
  44. ),
  45. );
  46. }
  47. function location_map_link_ch_default_providers() {
  48. return array('search', 'google');
  49. }
  50. function location_map_link_ch_google($location = array()) {
  51. $query_params = array();
  52. foreach (array('street', 'city', 'postal_code', 'country') as $field) {
  53. if (isset($location[$field])) {
  54. $query_params[] = $location[$field];
  55. }
  56. }
  57. if (count($query_params)) {
  58. return ('http://maps.google.ch?q='. urlencode(implode(', ', $query_params)));
  59. }
  60. else {
  61. return NULL;
  62. }
  63. }
  64. function location_map_link_ch_search($location = array()) {
  65. $query_param = '';
  66. if ($location['postal_code'] || $location['city'] || $location['street']) {
  67. $query_param = $location['postal_code'] . '-' . $location['city'] . '/' . $location['street'];
  68. return 'http://map.search.ch/' . $query_param;
  69. }
  70. else {
  71. return NULL;
  72. }
  73. }
  74. function location_driving_directions_link_ch($location_a, $location_b) {
  75. return _location_driving_directions_link_ch_search($location_a, $location_b);
  76. }
  77. function _location_driving_directions_link_ch_search($location_a, $location_b) {
  78. $query_params_a = array();
  79. $query_params_b = array();
  80. foreach (array('street', 'postal_code', 'city') as $field) {
  81. if (isset($location_a[$field])) {
  82. $query_params_a[] = $location_a[$field];
  83. }
  84. if (isset($location_b[$field])) {
  85. $query_params_b[] = $location_b[$field];
  86. }
  87. }
  88. return 'http://route.search.ch/?route=' . urlencode(implode(' ', $query_params_a) . ' to ' .implode(' ', $query_params_b));
  89. }
  90. /**
  91. * Returns minimum and maximum latitude and longitude needed to create a bounding box.
  92. */
  93. function location_bounds_ch() {
  94. return array(
  95. 'minlng' => 5.8814,
  96. 'minlat' => 45.7606,
  97. 'maxlng' => 10.58005,
  98. 'maxlat' => 47.693367,
  99. );
  100. }