예제 #1
0
 function getCoordinates($city, $state = '')
 {
     try {
         $coord = array();
         $coord['state'] = '';
         $coord['timezone'] = '';
         //Solr Request
         $query = "city_exact:\"" . trim($city) . "\"";
         if ($state != '') {
             $query .= " and state_exact:\"" . trim($state) . "\"";
         }
         $fields = 'zip-code,latitude,longitude,city,state,county';
         $this->solrQuery = new SolrQuery();
         $response = $this->solrQuery->getCoordByCity($query, $fields);
         if ($response->numFound > 0) {
             $coord['state'] = isset($response->docs[0]->state) ? $response->docs[0]->state : '';
             $coord['timezone'] = Timezone::getTimezone('US', $coord['state']);
         }
         return $coord;
     } catch (Exception $e) {
         logError('WeatherController::getCoordinates()', $e->getMessage());
     }
 }