在数据库上发布数据时发生“对未定义方法Geocoder \ Laravel \ Facades \ Geocoder :: getLatitude()的调用”错误。 使用地理编码包获取经度和纬度数据。
// Geocodeaddress.php->职位
public $model;
public function __construct($model){
$this->model = $model;
}
public function handle()
{
$result = new Geocoder();
$result = $this->model -> getAddressString();
$this->model->setCoordinates($result->getLatitude(), $result->getLongitude());
}
// RegisterController.php
protected function create(array $data)
{
//dd($data);
$user = User::create([
'fname' => $data['fname'],
'lname' => $data['lname'],
'email' => $data['email'],
'zipcode' => $data['zipcode'],
'latitude' => $data['latitude'],
'longitude' =>$data['longitude'],
'city' => $data['city'],
'state' => $data['state'],
'password' => Hash::make($data['password']),
'gender' => $data['gender'],
'dob' => $data['dob'],
'health' => $data['health'],
]);
//$this-> dispatch(new GeocodePartnerAddress($user));
$this->dispatch(new GeocodeAddress($user));
}
答案 0 :(得分:0)
您正在使用$ this-> model-> getAddressString();将$ result定义为字符串;
更改此:
public function handle()
{
$result = new Geocoder();
$result = $this->model -> getAddressString();
$this->model->setCoordinates($result->getLatitude(), $result->getLongitude());
}
对此:
public function handle() {
$result = new Geocoder();
$addressString = $this->model->getAddressString();
$this->model->setCoordinates($result->getLatitude(), $result->getLongitude());
}