location.no.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // Norway
  3. function location_province_list_no() {
  4. return array('AK' => "Akershus",
  5. 'AA' => "Aust-Agder",
  6. 'BU' => "Buskerud",
  7. 'FM' => "Finnmark",
  8. 'HM' => "Hedmark",
  9. 'HL' => "Hordaland",
  10. 'MR' => "More og Romdal",
  11. 'NL' => "Nordland",
  12. 'NT' => "Nord-Trondelag",
  13. 'OP' => "Oppland",
  14. 'OL' => "Oslo",
  15. 'OF' => "Ostfold",
  16. 'RL' => "Rogaland",
  17. 'SJ' => "Sogn og Fjordane",
  18. 'ST' => "Sor-Trondelag",
  19. 'TM' => "Telemark",
  20. 'TR' => "Troms",
  21. 'VA' => "Vest-Agder",
  22. 'VF' => "Vestfold");
  23. }
  24. function _location_latlon_rough_no($location = array()) {
  25. if (!isset($location['postal_code'])) {
  26. return NULL;
  27. }
  28. $row = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = :country AND zip = :zip", array(':country' => $location['country'], ':zip' => substr(str_pad($location['postal_code'], 5, '0', STR_PAD_LEFT), 0, 5)))->fetchObject();
  29. if ($row) {
  30. return array('lat' => $row->latitude, 'lon' => $row->longitude);
  31. }
  32. else {
  33. return NULL;
  34. }
  35. }
  36. /**
  37. * Returns a lat/lon pair of the approximate center of the given postal code in the given country
  38. *
  39. * @param $location
  40. * An associative array $location where only postal code and country are necessary, but can have the keys:
  41. * 'street' => the street portion of the location
  42. * 'supplemental' => additional street portion of the location
  43. * 'province' => the province, state, or territory
  44. * 'country' => lower-cased two-letter ISO code (REQUIRED)
  45. * 'postal_code' => the international postal code for this location (REQUIRED)
  46. *
  47. * @return
  48. * An associative array where
  49. * 'lat' => approximate latitude of the center of the postal code's area
  50. * 'lon' => approximate longitude of the center of the postal code's area
  51. * 'city' => the city
  52. * 'province' => the province, state, or territory
  53. * 'country' => lower-cased two-letter ISO code
  54. *
  55. */
  56. function _location_latlon_postalcode_no($location = array()) {
  57. // Now we pad the thing and query.
  58. #$res = db_query("SELECT * FROM {zipcodes} where country = '%s' AND zip = '%s'", $location['country'], str_pad($location['postal_code'], 4, "0", STR_PAD_LEFT));
  59. $row = db_query("SELECT * FROM {zipcodes} where country = :country AND zip = :zip", array(':country' => $location['country'], ':zip' => $location['postal_code']))->fetchObject();
  60. if ($row) {
  61. return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country);
  62. }
  63. else {
  64. return NULL;
  65. }
  66. }
  67. /**
  68. * Returns minimum and maximum latitude and longitude needed to create a bounding box.
  69. */
  70. function location_bounds_no() {
  71. return array(
  72. 'minlng' => -9.169,
  73. 'minlat' => 58.037433,
  74. 'maxlng' => 33.46415,
  75. 'maxlat' => 80.884167,
  76. );
  77. }