调用未定义的方法Spatie \ Geocoder \ Facades \ Geocoder :: getCoordinatesForAddress()

时间:2018-12-07 10:31:05

标签: laravel

这是我的代码。它给了我

  

错误:调用未定义的方法Spatie \ Geocoder \ Facades \ Geocoder :: getCoordinatesForAddress()

public function create()
{
    $subcategories = Subcategory::orderBy('subcategory_name', 'asc')->pluck('subcategory_name', 'id');
    // $client = new Client();
    $geocoder = new Geocoder();  

    // $geocoder->setApiKey(config('geocoder.key'));

    $Address = $geocoder->getCoordinatesForAddress('Samberstraat 69, Antwerpen, Belgium');
    $lat = $Address[0]->lat;
    dd($lat);

    return view('companies.create', compact('subcategories'));
}

1 个答案:

答案 0 :(得分:0)

如果使用外墙,则只需导入

use Spatie\Geocoder\Facades\Geocoder;

,您将其用作:

Geocoder::getCoordinatesForAddress('Samberstraat 69, Antwerpen, Belgium');

请注意,要使用外观,您需要按照安装过程(https://github.com/spatie/geocoder#laravel-installation)所述正确配置软件包

如果您喜欢使用该对象,则不导入Facade,而是导入类:

use Spatie\Geocoder\Geocoder;

您可以正常实例化该对象:

$geocoder = new Geocoder();  
// $geocoder->setApiKey(config('geocoder.key'));
$address = $geocoder->getCoordinatesForAddress('Samberstraat 69, Antwerpen, Belgium');