function nbpl_nights() { $zip = ''; $geocode = array(); if (!empty($_REQUEST['zip'])) { $zip = trim($_REQUEST['zip']); } $ObjVenueView = ClassRegistry::init("VenueView"); $conditions = array('VenueView.is_deleted' => 0, 'VenueView.nbpltype <> ' => 'None'); $order = array('VenueView.id' => 'DESC'); $fields = array('*'); if (!empty($zip)) { App::import('Vendor', 'GoogleMapAPI', array('file' => 'class.GoogleMapAPI.php')); $map = new GoogleMapAPI(); $map->setAPIKey(GOOGLE_MAP_KEY); $geocode = $map->geoGetCoords('UNITED STATES ' . $zip); if (!empty($geocode['lat']) && !empty($geocode['lon'])) { $fields[] = "(((acos(sin((" . $geocode['lat'] . " * pi()/180)) * sin((latitude*pi()/180)) + cos((" . $geocode['lat'] . " *pi()/180)) * cos((latitude * pi()/180)) \n\t\t\t\t* cos(((" . $geocode['lon'] . "- longitude)*pi()/180)))) * 180/pi()) * 60 *1.1515) as distance"; $order = array('distance' => 'ASC') + $order; } else { $zip = ''; $this->Session->setFlash('Incorrect Zip Code', 'flash_error'); } } $venues = $ObjVenueView->find('all', array('fields' => $fields, 'contain' => array('Nbplday'), 'conditions' => $conditions, 'order' => $order)); $this->set(compact('venues', 'zip', 'geocode')); }