diff --git a/README.md b/README.md index c58211d..fce7acf 100644 --- a/README.md +++ b/README.md @@ -36,15 +36,17 @@ You can search for elements using the location specified in your map field. When ```twig {% set entries = craft.entries.myMapField({ - location: 'Maidstone, Kent, UK', + location: 'Maidstone, Kent', + country: 'GB', radius: 100, unit: 'mi' -}).order('distance') %} +}).orderBy('distance').all() %} ``` -- `location`: Can either be an address string (requires a Google Maps Geocoding API key) or a Lat Lng Array (`{ 'lat': 51.27219908, 'lng': 0.51545620 }` or `craft.simpleMap.latLng(51.27219908, 0.51545620)`). -- `radius`: The radius around the location to search. Defaults to `50`. -- `unit`: The unit of measurement for the search. Can be either `km` (kilometers) or `mi` (miles). Defaults to `km`. +- `location`: Can either be an address string (requires a Google Maps Geocoding API key) or a Lat Lng Array (`{ 'lat': 51.27219908, 'lng': 0.51545620 }`). +- `country`: *Optional*. Restrict the search to a specific country (useful for non-specific searches, i.e. town name). Must be valid [2-letter ISO code](https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes) (recommended), or full country name. +- `radius`: *Optional*. The radius around the location to search. Defaults to `50`. +- `unit`: *Optional*. The unit of measurement for the search. Can be either `km` (kilometers) or `mi` (miles). Defaults to `km`. ### API Keys @@ -95,6 +97,10 @@ var map = new mapboxgl.Map({ ## Changelog +### 1.7.2 +- Added ability to restrict location search by country +- New icon! + ### 1.7.1 - It is now possible to save the field using only an address (useful for saving via the front-end, requires Geocoding). - Improved the field's validation. diff --git a/releases.json b/releases.json index cdecc66..d6e3844 100644 --- a/releases.json +++ b/releases.json @@ -183,5 +183,14 @@ "[Added] It is now possible to save the field using only an address (useful for saving via the front-end, requires Geocoding)", "[Improved] Improved the field's validation" ] + }, + { + "version": "1.7.2", + "downloadUrl": "https://github.com/ethercreative/simplemap/archive/v1.7.2.zip", + "date": "2017-11-28T14:10:00-08:00", + "notes": [ + "[Added] Added ability to restrict location search by country", + "[Changed] New icon!" + ] } ] diff --git a/simplemap/SimpleMapPlugin.php b/simplemap/SimpleMapPlugin.php index 003a6f4..7d465ff 100644 --- a/simplemap/SimpleMapPlugin.php +++ b/simplemap/SimpleMapPlugin.php @@ -24,7 +24,7 @@ public function getDescription() public function getVersion() { - return '1.7.1'; + return '1.7.2'; } public function getSchemaVersion() diff --git a/simplemap/resources/icon.svg b/simplemap/resources/icon.svg index ef756fd..56a2748 100644 --- a/simplemap/resources/icon.svg +++ b/simplemap/resources/icon.svg @@ -1,41 +1,15 @@ - - - - -icon -Created with Sketch. - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + icon + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/simplemap/services/SimpleMapService.php b/simplemap/services/SimpleMapService.php index 5234c5b..b6ec9d3 100644 --- a/simplemap/services/SimpleMapService.php +++ b/simplemap/services/SimpleMapService.php @@ -189,6 +189,7 @@ public function modifyQuery (DbCommand &$query, $params = array()) private function _searchLocation (DbCommand &$query, $params) { $location = $params['location']; + $country = array_key_exists('country', $params) ? $params['country'] : null; $radius = array_key_exists('radius', $params) ? $params['radius'] : 50.0; $unit = array_key_exists('unit', $params) ? $params['unit'] : 'kilometers'; @@ -198,7 +199,7 @@ private function _searchLocation (DbCommand &$query, $params) if (!in_array($unit, array('km', 'mi'))) $unit = 'km'; if (is_string($location)) - $location = self::getLatLngFromAddress($location); + $location = self::getLatLngFromAddress($location, $country); if (is_array($location)) { if (!array_key_exists('lat', $location) || !array_key_exists('lng', $location)) @@ -259,11 +260,13 @@ private function _searchLocation (DbCommand &$query, $params) * Find lat/lng from string address * * @param $address + * @param string|null $country + * * @return null|array * * TODO: Cache results? */ - public static function getLatLngFromAddress ($address) + public static function getLatLngFromAddress ($address, $country = null) { $browserApiKey = self::getAPIKey(); @@ -273,6 +276,9 @@ public static function getLatLngFromAddress ($address) . rawurlencode($address) . '&key=' . $browserApiKey; + if ($country) + $url .= '&components=country:' . rawurldecode($country); + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);