diff --git a/location.inc b/location.inc index 567f5d5..01d7940 100644 --- a/location.inc +++ b/location.inc @@ -146,15 +146,38 @@ function location_map_link_default_providers() { */ function location_map_link_google($location = array()) { $query_params = array(); + $location_fields = array( + 'street', + 'city', + 'province', + 'postal_code', + 'country', + ); - foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; + if (location_has_coordinates($location)) { + if (isset($location['locpick']['user_latitude'], $location['locpick']['user_longitude'])) { + $query_params = array( + $location['locpick']['user_latitude'], + $location['locpick']['user_longitude'] + ); + } + else { + $query_params = array( + $location['latitude'], + $location['longitude'] + ); + } + } + else { + foreach ($location_fields as $field) { + if (isset($location[$field])) { + $query_params[] = $location[$field]; + } } } if (count($query_params)) { - return ('http://maps.google.com?q=' . urlencode(implode(", ", $query_params))); + return ('https://www.google.com/maps?q=' . urlencode(implode(", ", $query_params))); } else { return NULL; diff --git a/location.module b/location.module index d82963b..54d881e 100644 --- a/location.module +++ b/location.module @@ -1379,16 +1379,17 @@ function location_has_coordinates($location, $canonical = FALSE) { if ($canonical) { return ($location['source'] != LOCATION_LATLON_UNDEFINED); } - + $latitude = isset($location['locpick']['user_latitude']) ? $location['locpick']['user_latitude'] : $location['latitude']; + $longitude = isset($location['locpick']['user_longitude']) ? $location['locpick']['user_longitude'] : $location['longitude']; // Otherwise, we need to do the full checks. // If latitude or longitude are empty/missing. - if (empty($location['latitude']) || empty($location['longitude'])) { + if (empty($latitude) || empty($longitude)) { return FALSE; } // If the latitude or longitude are zeroed (Although it could be a good idea to relax this slightly sometimes). - if (_location_floats_are_equal($location['latitude'], 0.0) || _location_floats_are_equal( - $location['longitude'], + if (_location_floats_are_equal($latitude, 0.0) || _location_floats_are_equal( + $longitude, 0.0 ) ) { diff --git a/supported/location.au.inc b/supported/location.au.inc index 9014963..5e0265c 100644 --- a/supported/location.au.inc +++ b/supported/location.au.inc @@ -167,20 +167,7 @@ function location_map_link_au_yahoo($location = array()) { * Google link. */ function location_map_link_au_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.com?q=' . urlencode(implode(", ", $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.be.inc b/supported/location.be.inc index 9607c54..c703f48 100644 --- a/supported/location.be.inc +++ b/supported/location.be.inc @@ -64,18 +64,5 @@ function location_map_link_be_default_providers() { * Google link. */ function location_map_link_be_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.be?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } diff --git a/supported/location.ca.inc b/supported/location.ca.inc index 37c4a24..c94ed77 100644 --- a/supported/location.ca.inc +++ b/supported/location.ca.inc @@ -154,20 +154,7 @@ function location_map_link_ca_yahoo($location = array()) { * Google link. */ function location_map_link_ca_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.ca?q=' . urlencode(implode(", ", $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.ch.inc b/supported/location.ch.inc index 4fc41d8..92b556e 100644 --- a/supported/location.ch.inc +++ b/supported/location.ch.inc @@ -68,20 +68,7 @@ function location_map_link_ch_default_providers() { * Google link. */ function location_map_link_ch_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.ch?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.cn.inc b/supported/location.cn.inc index 86c2c5c..bc0bfd9 100644 --- a/supported/location.cn.inc +++ b/supported/location.cn.inc @@ -71,20 +71,7 @@ function location_map_link_cn_default_providers() { * Google link. */ function location_map_link_cn_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.com.hk?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.cz.inc b/supported/location.cz.inc index 3bdf6a7..1eb15b7 100644 --- a/supported/location.cz.inc +++ b/supported/location.cz.inc @@ -51,20 +51,7 @@ function location_map_link_cz_default_providers() { * Google link. */ function location_map_link_cz_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.cz?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.de.inc b/supported/location.de.inc index 8f65dcb..2966364 100644 --- a/supported/location.de.inc +++ b/supported/location.de.inc @@ -197,20 +197,7 @@ function _location_driving_directions_link_de_suchen($location_a, $location_b) { * Google link. */ function location_map_link_de_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'postal_code', 'city', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.com?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.fr.inc b/supported/location.fr.inc index b8770cd..84c5fff 100644 --- a/supported/location.fr.inc +++ b/supported/location.fr.inc @@ -138,18 +138,5 @@ function location_map_link_fr_default_providers() { * Google link. */ function location_map_link_fr_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.fr/?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } diff --git a/supported/location.gb.inc b/supported/location.gb.inc index cd82c58..3c6a59c 100644 --- a/supported/location.gb.inc +++ b/supported/location.gb.inc @@ -159,20 +159,7 @@ function location_map_link_gb_default_providers() { * Google link. */ function location_map_link_gb_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.co.uk?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.gr.inc b/supported/location.gr.inc index 0a4a93b..d335427 100644 --- a/supported/location.gr.inc +++ b/supported/location.gr.inc @@ -42,32 +42,7 @@ function location_bounds_gr() { * Google link. */ function location_map_link_gr_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'province', 'postal_code') as $field) { - if (isset($location[$field]) && $location[$field] != '') { - $query_params[] = $location[$field]; - } - } - // Country always exists. - if (count($query_params) != 0 && isset($location['country']) && $location['country'] != '') { - $query_params[] = $location['country']; - } - // When no address provided, but coordinates do, link to coordinates. - if (count($query_params) == 0) { - foreach (array('latitude', 'longitude') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - } - - if (count($query_params)) { - return ('http://maps.google.com?q=' . urlencode(implode(", ", $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.my.inc b/supported/location.my.inc index 7c6d25b..50c6da2 100644 --- a/supported/location.my.inc +++ b/supported/location.my.inc @@ -82,28 +82,7 @@ function location_map_link_my_default_providers() { * Google link. */ function location_map_link_my_google($location = array()) { - $query_params = array(); - $q = NULL; - - foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (location_has_coordinates($location)) { - $q = urlencode($location['latitude'] . ' ' . $location['longitude'] . ' (' . implode(', ', $query_params) . ')'); - } - elseif (count($query_params) > 0) { - $q = urlencode(implode(", ", $query_params)); - } - - if ($q != NULL) { - return ('http://maps.google.com.my?q=' . $q); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.nl.inc b/supported/location.nl.inc index 61b28d0..82cfc3f 100644 --- a/supported/location.nl.inc +++ b/supported/location.nl.inc @@ -49,20 +49,7 @@ function location_map_link_nl_default_providers() { * Google link. */ function location_map_link_nl_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.nl?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.nz.inc b/supported/location.nz.inc index a9fe740..1310c62 100644 --- a/supported/location.nz.inc +++ b/supported/location.nz.inc @@ -263,20 +263,7 @@ function location_map_link_nz_yahoo($location = array()) { * URL */ function location_map_link_nz_google($location = array()) { - $query_params = array(); - - foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (count($query_params)) { - return ('http://maps.google.com?q=' . urlencode(implode(", ", $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } /** diff --git a/supported/location.pt.inc b/supported/location.pt.inc index c4efac6..02d290b 100644 --- a/supported/location.pt.inc +++ b/supported/location.pt.inc @@ -57,35 +57,5 @@ function location_map_link_pt_default_providers() { * Google link. */ function location_map_link_pt_google($location = array()) { - $query_params = array(); - $q = NULL; - - foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (location_has_coordinates($location)) { - $q = urlencode($location['latitude'] . ' ' . $location['longitude'] . ' (' . implode(', ', $query_params) . ')'); - } - else { - if (count($query_params) > 0) { - $q = urlencode(implode(", ", $query_params)); - } - } - - if ($q != NULL) { - return ('http://maps.google.pt?q=' . $q); - } - else { - return NULL; - } - - if (count($query_params)) { - return ('http://maps.google.pt?q=' . urlencode(implode(', ', $query_params))); - } - else { - return NULL; - } + return location_map_link_google($location); } diff --git a/supported/location.us.inc b/supported/location.us.inc index fe7a6a7..4e8a2d0 100644 --- a/supported/location.us.inc +++ b/supported/location.us.inc @@ -180,30 +180,7 @@ function location_map_link_us_yahoo($location = array()) { * Google link. */ function location_map_link_us_google($location = array()) { - $query_params = array(); - $q = NULL; - - foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) { - if (isset($location[$field])) { - $query_params[] = $location[$field]; - } - } - - if (location_has_coordinates($location)) { - $q = urlencode($location['latitude'] . ' ' . $location['longitude'] . ' (' . implode(', ', $query_params) . ')'); - } - else { - if (count($query_params) > 0) { - $q = urlencode(implode(", ", $query_params)); - } - } - - if ($q != NULL) { - return ('http://maps.google.com?q=' . $q); - } - else { - return NULL; - } + return location_map_link_google($location); } /**