<?php

namespace App\Repositories\Core;

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

            $geocode = app('geocoder')->geocode($address)->get();
            
            if (count($geocode)) {
                $res = $geocode[0]->getCoordinates()->toArray();
                // dump($res);
                $longitude = $res[0];
                $latitude = $res[1];
                // dump($latitude);
                // dump($longitude);
                // exit;
                return ['latitude' => $latitude, 'longitude' => $longitude];
            } else {
                return false;
            }
        }
    }

    public static function autocomplete($query)
    {
    }
}
