<?php

namespace App\Repositories\Core;

class Geolocation
{
    public static function getCoords($address, $zipcode, $city)
    {
        if (! (! empty($address) && ! empty($zipcode) && ! empty($city))) {
            return;
        }
        $address = $address.' , '.$city.' '.$zipcode.' , '.'France';

        $geocode = app('geocoder')->geocode($address)->get();

        if (! count($geocode)) {
            return false;
        }
        $res = $geocode[0]->getCoordinates()->toArray();
        // dump($res);
        $longitude = $res[0];
        $latitude = $res[1];

        // dump($latitude);
        // dump($longitude);
        // exit;
        return ['latitude' => $latitude, 'longitude' => $longitude];

    }

    public static function autocomplete($query)
    {
    }
}
