function get_places($lat, $long, $radius, $types, $res_temp_1) { $google_places = new joshtronic\GooglePlaces('AIzaSyARM9C4EtyNYH0mSk-iyUtAoEnj_8Yrixs'); $google_places->location = array($lat, $long); $google_places->radius = $radius; $google_places->output = 'json'; $google_places->keyword = $types; $results = $google_places->nearbySearch(); $r = $results['results']; #var_dump($r); #$res_final = explode(' ' ,$res_final); #var_dump($res_temp_1); foreach ($r as $x) { $x = $x['types']; foreach ($x as $y) { if ($topics[$y] != '') { $topics[$y] = $topics[$y] + 1; } else { $topics[$y] = 1; } } foreach ($res_temp_1 as $a => $b) { #echo $a; if ($topics[$a] != '') { $topics[$a] = $topics[$a] + 1; } else { $topics[$a] = 1; } } #var_dump($x['types']); } #echo "something"; arsort($topics); #array_push($temp, "tourist destinations", "budget travel", "adventure","leisure","trekking","sightseeing"); #shuffle($topics); # #$temp = $topics; foreach ($topics as $x => $y) { $temp[] = $x; } $topics = $temp; #$topics = array_slice($temp, 0, 7); $pre = str_replace("%20", "&", $_GET["pre"]); $pre = str_replace(" ", "&", $_GET["pre"]); $pre_a = explode('&', $pre); $pre_arr = array(); for ($i = 0; $i < count($pre_a); $i++) { $pre_arr[$pre_a[$i]] = True; } #var_dump($pre_arr); for ($i = 0; $i < count($topics); $i++) { #echo $topics[$i]; if ($topics[$i] != null && !isset($pre_arr[$topics[$i]])) { $final_answer['categories'][] = $topics[$i]; } #echo '<form action="'.$PHP_SELF.'" method = "GET"><input type="hidden" name="types" value="'.$key.'"><button type="submit">'.$key.' </button></form>'; } #var_dump($final_answer); $i = 0; foreach ($r as $x) { #var_dump($x); $final_answer['title'][$i]['name'] = $x['name']; $final_answer['title'][$i]['icon'] = $x['icon']; $final_answer['title'][$i]['lat'] = $x['geometry']['location']['lat']; $final_answer['title'][$i]['lng'] = $x['geometry']['location']['lng']; $final_answer['title'][$i]['vicinity'] = $x['vicinity']; $i = $i + 1; #echo '<tr><td>'.$x['name'].'</td></tr>'; } $answer = json_encode($final_answer); header('Content-Type: application/json'); echo $answer; #var_dump( $answer); }
public function ksearch() { $latmsg = ""; $longmsg = ""; $keymsg = ""; $capmsgx = ""; $e = 0; $f = 0; if (!isset($_POST['latitude']) || empty($_POST['latitude'])) { $latmsg = "Please click anywhere on the map to get search coordinates."; $e++; } if (!isset($_POST['longitude']) || empty($_POST['longitude'])) { $longmsg = "Please click anywhere on the map to get search coordinates."; $e++; } if (!isset($_POST['keyword']) || empty($_POST['keyword'])) { $keymsg = "Please enter a keyword."; $e++; } if (!isset($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_challenge_field']) || (!isset($_POST['recaptcha_response_field']) || empty($_POST['recaptcha_response_field']))) { $capmsgx = "Please enter captcha."; $e++; } //All input fields are NOT populated if ($e !== 0) { $ret[0]['field'] = "latmsg"; $ret[0]['value'] = $latmsg; $ret[1]['field'] = "longmsg"; $ret[1]['value'] = $longmsg; $ret[2]['field'] = "capmsgx"; $ret[2]['value'] = $capmsgx; $ret[3]['field'] = "keymsg"; $ret[3]['value'] = $keymsg; $ret[4]['field'] = "pres"; $ret[4]['value'] = ""; } else { $ip = $this->input->ip_address(); $ip = (string) $ip; $rcf = $_POST['recaptcha_challenge_field']; $rrf = $_POST['recaptcha_response_field']; $capresp = $this->checkcaptcha($ip, $rcf, $rrf); //Wrong Captcha if (!$capresp) { $capmsgx = "Wrong Captcha. Please try again"; $ret[0]['field'] = "latmsg"; $ret[0]['value'] = $latmsg; $ret[1]['field'] = "longmsg"; $ret[1]['value'] = $longmsg; $ret[2]['field'] = "capmsgx"; $ret[2]['value'] = $capmsgx; $ret[3]['field'] = "keymsg"; $ret[3]['value'] = $keymsg; $ret[4]['field'] = "pres"; $ret[4]['value'] = ""; } else { $lat = $_POST['latitude']; $long = $_POST['longitude']; $keyword = $_POST['keyword']; $lat = floatval($lat); $long = floatval($long); $google_places = new joshtronic\GooglePlaces('AIzaSyAd7wY5X1Vfc2KGa2xo1gzFbHe2Qve0FA4'); $google_places->location = array($lat, $long); $google_places->rankby = 'distance'; $google_places->types = (string) $keyword; $results = $google_places->nearbySearch(); $marr = array(); $i = 0; //$str = ""; $resarr = array(); $resarr['html_attributions'] = $results['html_attributions']; if (array_key_exists('next_page_token', $results)) { $resarr['next_page_token'] = $results['next_page_token']; } else { $resarr['next_page_token'] = ""; } $j = 0; if (array_key_exists('results', $results)) { if (!empty($results['results'])) { foreach ($results['results'] as $value) { $resarr['results'][$i]['lat'] = $value['geometry']['location']['lat']; $resarr['results'][$i]['lng'] = $value['geometry']['location']['lng']; if (array_key_exists('icon', $value)) { $resarr['results'][$i]['icon'] = $value['icon']; } else { $resarr['results'][$i]['icon'] = ''; } if (array_key_exists('id', $value)) { $resarr['results'][$i]['id'] = $value['id']; } else { $resarr['results'][$i]['id'] = ''; } if (array_key_exists('name', $value)) { $resarr['results'][$i]['name'] = $value['name']; } else { $resarr['results'][$i]['name'] = ''; } if (array_key_exists('place_id', $value)) { $resarr['results'][$i]['place_id'] = $value['place_id']; } else { $resarr['results'][$i]['place_id'] = ''; } if (array_key_exists('rating', $value)) { $resarr['results'][$i]['rating'] = $value['rating']; } else { $resarr['results'][$i]['rating'] = ''; } if (array_key_exists('reference', $value)) { $resarr['results'][$i]['reference'] = $value['reference']; } else { $resarr['results'][$i]['reference'] = ''; } if (array_key_exists('scope', $value)) { $resarr['results'][$i]['scope'] = $value['scope']; } else { $resarr['results'][$i]['scope'] = ''; } if (array_key_exists('types', $value)) { $resarr['results'][$i]['types'] = $value['types']; } else { $resarr['results'][$i]['types'] = ''; } if (array_key_exists('vicinity', $value)) { $resarr['results'][$i]['vicinity'] = $value['vicinity']; } else { $resarr['results'][$i]['vicinity'] = ''; } if (array_key_exists('photos', $value)) { $resarr['results'][$i]['photos'] = $value['photos']; } else { $resarr['results'][$i]['photos'] = ''; } $i++; } } else { $resarr['results'] = null; } } else { $resarr['results'] = null; } $str = ""; if (!empty($resarr['results'])) { $str .= "<table class=\"table table-hover\">"; $str .= "<thead>"; $str .= "<tr>"; $str .= "<th>Latitude</th>"; $str .= "<th>Longitude</th>"; $str .= "<th>Place Name</th>"; $str .= "<th>Type</th>"; $str .= "</tr>"; $str .= "</thead>"; $str .= "<tbody>"; foreach ($resarr['results'] as $value1) { $marr[$j]["latitude"] = floatval($value1["lat"]); $marr[$j]["longitude"] = floatval($value1["lng"]); $marr[$j]["name"] = $value1["name"]; $marr[$j]["info"] = "<p>" . $value1["name"] . "</p>"; //$str .= $value1['lat']." ".$value1['lng']." ".$value1['name']."<br />"; //$str .= $marr[$j]["latitude"]." ".$marr[$j]["longitude"]." ".$marr[$j]["info"]."<br />"; $type = ""; if (!empty($value1['types'])) { $type = $value1['types'][0]; } $str .= "<tr>"; $str .= "<td>" . $value1["lat"] . "</td>"; $str .= "<td>" . $value1["lng"] . "</td>"; $str .= "<td>" . $value1["name"] . "</td>"; $str .= "<td>" . $type . "</td>"; $str .= "</tr>"; $j++; } $str .= "</tbody>"; $str .= "</table>"; } //var_dump($marr); // $marr[0]['latitude'] = "34.0742216117106"; // $marr[0]['longitude'] = "-118.18885803222656"; // $marr[0]['info'] = "<p>A</p>"; // $marr[1]['latitude'] = "34.044072125158074"; // $marr[1]['longitude'] = "-118.23040008544922"; // $marr[1]['info'] = "<p>B</p>"; // $marr[2]['latitude'] = "34.02970468333924"; // $marr[2]['longitude'] = "-118.28670501708984"; // $marr[2]['info'] = "<p>C</p>"; // $marr[3]['latitude'] = "34.06654304353127"; // $marr[3]['longitude'] = "-118.29357147216797"; // $marr[3]['info'] = "<p>D</p>"; $ret[0]['field'] = "latmsg"; $ret[0]['value'] = $latmsg; $ret[1]['field'] = "longmsg"; $ret[1]['value'] = $longmsg; $ret[2]['field'] = "capmsgx"; $ret[2]['value'] = $capmsgx; $ret[3]['field'] = "keymsg"; $ret[3]['value'] = $keymsg; $ret[4]['field'] = "pres"; $ret[4]['value'] = $str; $ret[5]['field'] = "mdata"; $ret[5]['value'] = $marr; } } header('Content-Type: application/x-json; charset=utf-8'); echo json_encode($ret); }
$stmt->free_result(); } // Places Search API object $places = new joshtronic\GooglePlaces(GOOGLE_SERVER_KEY); $places->location = array($arguments['latitude'], $arguments['longitude']); $places->radius = $arguments['maxdistance']; $places->types = array('restaurant', 'food'); $places->keyword = 'food'; $places->opennow = true; $places->minprice = $arguments['minprice']; $places->maxprice = $arguments['maxprice']; if (array_key_exists('pagetoken', $arguments)) { // Retrieves next page of results $places->pagetoken = $arguments['pagetoken']; } $search = $places->nearbySearch(); $search['browserapikey'] = GOOGLE_BROWSER_KEY; // Return all rows in addlocations // Could have database calculate distance and return within bounds, not enough rows yet to justify duplicate code $queryaddlocations = <<<SQL SELECT * FROM `addlocations` SQL; $queryaddlocationsresult = $db->query($queryaddlocations); // Insert all businesses into results array, we'll calculate distances and cut off later while ($row = $queryaddlocationsresult->fetch_assoc()) { $newbusiness = array(); $newbusiness['geometry']['location']['lat'] = $row['latitude']; $newbusiness['geometry']['location']['lng'] = $row['longitude']; $newbusiness['place_id'] = $row['id']; $newbusiness['name'] = $row['name']; $newbusiness['image_url'] = $row['imageurl'];