Skip to content

Commit 20ccabc

Browse files
authored
Merge pull request #106 from goodevilgenius/add-zipcode-search
Add search by zip
2 parents b621e20 + 10d4c29 commit 20ccabc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Cmfcmf/OpenWeatherMap.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,13 @@ public function getApiKey()
179179
*
180180
* @return CurrentWeather The weather object.
181181
*
182-
* There are three ways to specify the place to get weather information for:
182+
* There are four ways to specify the place to get weather information for:
183183
* - Use the city name: $query must be a string containing the city name.
184184
* - Use the city id: $query must be an integer containing the city id.
185185
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
186+
* - Use the zip code: $query must be a string, prefixed with "zip:"
187+
*
188+
* Zip code may specify country. e.g., "zip:77070" (Houston, TX, US) or "zip:500001,IN" (Hyderabad, India)
186189
*
187190
* @api
188191
*/
@@ -670,6 +673,9 @@ private function buildQueryUrlParameter($query)
670673
return 'id='.implode(',', $query);
671674
case is_numeric($query):
672675
return "id=$query";
676+
case is_string($query) && strpos($query, 'zip:') === 0:
677+
$subQuery = str_replace('zip:', '', $query);
678+
return 'zip='.urlencode($subQuery);
673679
case is_string($query):
674680
return 'q='.urlencode($query);
675681
default:

0 commit comments

Comments
 (0)