public function gpois($lat, $lng, $type = 'restaurant') { $url = "https://www.google.fr/search?tbm=map&fp=1&authuser=0&hl=fr&pb=!4m12!1m3!1d4073.5434512203738!2d{$lng}!3d{$lat}!2m3!1f0!2f0!3f0!3m2!1i1360!2i298!4f13.1!7i10!10b1!12m6!2m3!5m1!2b0!20e3!10b1!16b1!19m3!2m2!1i392!2i106!20m40!2m2!1i203!2i200!3m1!2i4!6m6!1m2!1i86!2i86!1m2!1i408!2i256!7m26!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e3!2b1!3e2!2b1!4b0!9b0!7e81!24m1!2b1!26m3!2m2!1i80!2i92!30m28!1m6!1m2!1i0!2i0!2m2!1i458!2i298!1m6!1m2!1i1310!2i0!2m2!1i1360!2i298!1m6!1m2!1i0!2i0!2m2!1i1360!2i20!1m6!1m2!1i0!2i278!2m2!1i1360!2i298!37m1!1e81&q=" . urlencode($type); $data = xCache('gpois.' . sha1(serialize(func_get_args()) . $type), function () use($url) { return lib('geo')->dwn($url); }, strtotime('+6 month')); $data = str_replace("\n", "", $data); $data = str_replace("\r", "", $data); $data = str_replace("\t", "", $data); $data = str_replace(")]}'", "", $data); $data = json_decode($data, true); $tab = $data[0][1]; array_shift($tab); $collection = []; foreach ($tab as $row) { $latRow = $row[14][9][2]; $lngRow = $row[14][9][3]; $distances = distanceKmMiles($lng, $lat, $lngRow, $latRow); $name = $row[14][11]; $ws = $row[14][7][0]; $tel = $row[14][3][0]; $address = $row[14][2][0] . ', ' . $row[14][2][1]; $price = $row[14][4][2]; $rate = floatval($row[14][4][7]); $avis = (int) $row[14][4][8]; $type = $row[14][13][0]; $hexa = $row[14][10]; $label = $row[14][18]; $link = $row[14][4][3][0]; if (strstr($link, 'ludocid')) { $cid = 'g' . Utils::cut('ludocid=', '#', $link); } else { $cid = 'g' . Utils::cut('.com/', '/', $row[6][1]); } $horaires = $row[14][34][1]; $abstract = $row[14][32][0][1] . '. ' . $row[14][32][1][1]; $obj = ['distance' => $distances['km'] * 1000, 'hexa' => $hexa, 'cid' => $cid, 'type' => $type, 'label' => $label, 'abstract' => $abstract, 'name' => $name, 'lat' => $latRow, 'lng' => $lngRow, 'website' => $ws, 'phone' => $tel, 'address' => $address, 'rate' => $rate, 'avis' => $avis, 'price' => $price, 'schedule' => $this->schedule($horaires), 'img_in' => 'http:' . $row[14][37][0][1][6][0], 'img_out' => 'http:' . $row[14][37][0][2][6][0]]; if ($obj['img_in'] == 'http:') { continue; } else { $obj['img_in'] .= '&w=600&h=400'; } if ($obj['img_out'] == 'http:') { $obj['img_out'] = null; } else { $obj['img_out'] .= '&w=600&h=400'; } if ($obj['cid'] == 'g') { $obj['cid'] = null; Model::FeatureMap()->firstOrCreate(['fid' => 'g' . $hexa]); } else { Model::FeatureMap()->firstOrCreate(['fid' => $cid]); } $collection[] = $obj; } $collection = coll($collection)->sortBy('distance')->toArray(); $collection = array_values($collection); return $collection; }