How do I get the longitude and latitude where the user is in laravel?

1

I write this time because how can I get the longitude and latitude of the user who started the session ?, am I working with laravel or should I add google maps, also how can I get the 10 closest cities? although if it does not find the same I visualize 10 cities no matter that they are not close, I have programmed it until this part but they recommend that I must annex it.

 public function index(Request $request)
{
    //Valores iniciales del usuario
    $latitud_user=1.872452;
    $longitud_user=15.941253;
    $radius=1;

    $haversine = "(6371 * acos(cos(radians($latitud_user)) 
                 * cos(radians(latitud)) 
                 * cos(radians(longitud) 
                 - radians($longitud_user)) 
                 + sin(radians($latitud_user)) 
                 * sin(radians(latitud))))";

    if(!$request->ajax())
    {
        $ciudades= Ciudad::select() //pick the columns you want here.
                    ->selectRaw("{$haversine} AS distance")
                    ->whereRaw("{$haversine} < ?", [$radius])->paginate(10);

        $result_count = count($ciudades);

        return view('ciudades.index', compact('ciudades','result_count'));
    }else{
        if($request->isNombre == 1)     
        {
            $ciudades= Ciudad::select()->selectRaw("{$haversine} AS distance")->where('nombre','like', '%' . $request->buscar . '%')
                    ->whereRaw("{$haversine} < ?", [$radius])->paginate(10);
        }else if($request->isCiudad == 1)       
        {
            $ciudades= Ciudad::select()->selectRaw("{$haversine} AS distance")->where('ciudad','like', '%' . $request->buscar . '%')
                    ->whereRaw("{$haversine} < ?", [$radius])->paginate(10);
        }
        $result_count = count($ciudades);
        return response()->json(view('ciudades.partials.listado', compact('ciudades','result_count'))->render());
    }   
}

If you can help me, I would appreciate it.

    
asked by Miranda 27.11.2018 в 13:28
source

0 answers