/** * @param $origin * @param $destination * @return string */ public static function getFlightPath($origin, $destination) { $array = []; // FORMAT // $array = [ // 0 => [lat,lng], // 1 => [lat,lng] // ]; $array[0] = Geohelper::parseLongLat($origin); $array[1] = Geohelper::parseLongLat($destination); $path = Geohelper::encode($array); return $path; }
/** * @param $token * @param iterinary_id * @param $destination_name * @param $lng * @param $price * @param $lat * @return \Illuminate\Http\JsonResponse */ public static function endSegment($token, $iterinary_id, $destination_name, $lng, $lat, $price = 0) { $iterinary = Iterinary::find($iterinary_id); $route = $iterinary->route; $segment = $route->segments()->where('destination_name', '=', '')->orWhere('destination_name', '=', 'null')->first(); $segment->destination_name = $destination_name; $segment->destination_pos = $lat . ',' . $lng; $segment->price = $price; $segment->distance = GeolocationHelper::calculateDistance($segment); $segment->duration = GeolocationHelper::calculateDuration($segment); $points = array_merge(GeolocationHelper::parseLongLat($segment->origin_pos), [$lng, $lat]); // update activity model $activity = $segment->activity; foreach ($activity as $item) { //add ent time to activity $item->end_time = Carbon::now()->toTimeString(); $item->save(); } // $segment->path = GeolocationHelper::encode($points); if ($segment->save()) { $iterinary = Iterinary::findOrFail($iterinary_id)->with('activities.typable')->first(); return response()->json($iterinary, 200); } return response()->json('error', 403); }