function funcYelpApi($need, $loc) { ///The users inputs global $whatTheyWantToFind; $whatTheyWantToFind = str_replace(' ', '+', $need); $whereTheyWantToFind = str_replace(' ', '+', $loc); query_api($whatTheyWantToFind, $whereTheyWantToFind); }
#!/usr/bin/php <?php /** * Yelp API v2.0 code sample. * * This program demonstrates the capability of the Yelp API version 2.0 * by using the Search API to query for businesses by a search term and location, * and the Business API to query additional information about the top result * from the search query. * * Please refer to http://www.yelp.com/developers/documentation for the API documentation. * * This program requires a PHP OAuth2 library, which is included in this branch and can be * found here: * http://oauth.googlecode.com/svn/code/php/ * * Sample usage of the program: * `php sample.php --term="bars" --location="San Francisco, CA"` */ // Enter the path that the oauth library is in relation to the php file /** * User input is handled here */ $longopts = array("term::", "location::"); $options = getopt("", $longopts); $term = $options['term'] ?: ''; $location = $options['location'] ?: ''; query_api($term, $location);
return $allBusinessData; } /** * User input is handled here */ $longopts = array("term::", "location::"); $options = getopt("", $longopts); $term = $options['term'] ?: ''; $location = $options['location'] ?: ''; $final = array(); $overall = 1; for ($i = 1; $i < 8; $i++) { $numEntered = 1; $choice = 1; $CATEGORY_FILTER = $nameOfType["{$i}"]; $allBusinessData = query_api($term, $location); // var_dump($numOfType["$i"]); // var_dump($allBusinessData); while ($numEntered <= $numOfType["{$i}"]) { // print"\nOverall "; print($overall); // var_dump(in_array($allBusinessData["names"][$choice],$ignoredPlaces)); // var_dump($allBusinessData["names"][$choice]); // if (in_array($allBusinessData["names"][$choice],$ignoredPlaces)){ // $choice++; // // $overall--; // } // else{ $final["names"][$overall] = $allBusinessData["names"][$choice]; $final["type"][$overall] = $allBusinessData["type"][$choice]; $final["location"][$overall] = $allBusinessData["location"][$choice]; $final["image"][$overall] = $allBusinessData["image"][$choice];
function buildJSON() { $output = '{'; $output .= '"Boulder":['; $output .= query_api('restaurants', 'Boulder, CO') . ','; $output .= query_api('active', 'Boulder, CO') . ','; $output .= query_api('nightlife', 'Boulder, CO') . ','; $output .= query_api('arts', 'Boulder, CO') . '],'; $output .= '"Fort Collins":['; $output .= query_api('restaurants', 'Fort Collins, CO') . ','; $output .= query_api('active', 'Fort Collins, CO') . ','; $output .= query_api('nightlife', 'Fort Collins, CO') . ','; $output .= query_api('arts', 'Fort Collins, CO') . '],'; $output .= '"Denver":['; $output .= query_api('restaurants', 'Denver, CO') . ','; $output .= query_api('active', 'Denver, CO') . ','; $output .= query_api('nightlife', 'Denver, CO') . ','; $output .= query_api('arts', 'Denver, CO') . ']'; $output .= '}'; echo $output; }
$business_id = $response->businesses[0]->id; $allBusinessData = array("names" => array(), "location" => array(), "type" => array(), "image" => array(), "phone" => array(), "address" => array()); for ($i = 1; $i < 15; $i++) { $bus = $response->businesses[$i]->image_url; $start = strpos($bus, 'bphoto') + 7; $end = strpos($bus, '/ms'); $full_url = substr($bus, $start, $end - $start); $full_url = "http://s3-media4.fl.yelpcdn.com/bphoto/{$full_url}/o.jpg"; $allBusinessData["names"][$i] = $response->businesses[$i]->name; $allBusinessData["type"][$i] = $response->businesses[$i]->categories[0][0]; $allBusinessData["location"][$i] = $response->businesses[$i]->location->coordinate; $allBusinessData["image"][$i] = $full_url; $allBusinessData["phone"][$i] = $response->businesses[$i]->phone; $allBusinessData["address"][$i] = $response->businesses[$i]->location->display_address; } return $allBusinessData; } /** * User input is handled here */ $longopts = array("term::", "location::"); $options = getopt("", $longopts); $term = $options['term'] ?: ''; $location = $options['location'] ?: ''; // $final = array(); // for ($i = 1; $i < 8; $i++) // while $retval = query_api($term, $location); //echo("Query Returned \n"); // var_dump($retval); echo json_encode($retval);
// "%d businesses found, querying business info for the top result \"%s\"\n\n", // count($response->businesses), // $business_id // ); // $response = get_business($business_id); // print sprintf("Result for business \"%s\" found:\n", $business_id); // print "$response\n"; // } print count($response->businesses); foreach ($response->businesses as $business) { $business_id = $business->id; // print sprintf( // "%d businesses found, querying business info for the top result \"%s\"\n\n", // 3, // $business_id // ); $response = get_business($business_id); // print sprintf("Result for business \"%s\" found:\n", $business_id); print "{$response}\n"; } } /** * User input is handled here */ $longopts = array("term::", "location::", "category_filter::"); $options = getopt("", $longopts); $term = $options['term'] ?: ''; $location = $options['location'] ?: ''; $category_filter = $options['category_filter'] ?: ''; query_api($term, $location, $category_filter);
$dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return $miles * 1.609344; } else { if ($unit == "N") { return $miles * 0.8683999999999999; } else { return $miles; } } } header('Content-Type: application/json'); try { list($x, $y) = get_params($_GET); $data['user']['x'] = $x; $data['user']['y'] = $y; $airports = get_nearest_airport($data); } catch (Exception $e) { echo json_encode(array("err" => $e->getMessage())); return; } // print_r(json_encode($airports, JSON_PRETTY_PRINT)); $data = query_api($airports['nearest']); $data = array_merge($data, $airports); // $data['dist_to_airport'] = calc_distance($airports['nearest'], $data['user']); // $data['dist_to_food'] = calc_distance($airports['nearest'], $data); $data['dist_to_airport'] = coords_to_distance($airports['nearest']['x'], $airports['nearest']['y'], $data['user']['x'], $data['user']['y']); $data['dist_to_food'] = coords_to_distance($airports['nearest']['x'], $airports['nearest']['y'], $data['user']['x'], $data['user']['y']); echo json_encode($data, JSON_PRETTY_PRINT);