douxian1892 2019-05-13 09:57
浏览 51
已采纳

在laravel中使用地理编码包时出现“No provider registered”错误

https://github.com/geocoder-php/GeocoderLaravel/blob/master/config/geocoder.php I cant get pass this point. 1. this is my Job


        public $model;

            public function __construct($model)
            {
                $this->model = $model;
            }

            public function handle()
            {
                $result = new Geocoder();
                $result->geocode($this->model->getAddressString());
              // $result = Geocoder::geocode($this->model->getAddressString());

                $this->model->setCoordinates($result->getLatitude(), $result->getLongitude());
            }
        }
         I followed the instructions in the repo readme to install geocoder into my project.
        2. this is my controller

On trying to get Langitude and latitude from address , i get the no provider registered error..

         protected function create(array $data)
            {                    

                $user =  User::create([
                    'fname' => $data['fname'],
                    'lname' => $data['lname'],
                    'email' => $data['email'],
                    'zipcode' => $data['zipcode'],
                    'address_latitude' => $data['address_latitude'],
                    'address_longitude' =>$data['address_longitude'],
                    'password' => Hash::make($data['password']),
                    'gender' => $data['gender'],

                    'dob' => $data['dob'],

                    'health' => $data['health'],
                ]); 

               //$this-> dispatch(new GeocodePartnerAddress($user)); 
                 $this->dispatch(new GeocodeAddress($user));

            }

On trying to get Langitude and latitude from address , i get the no provider registered error..

    I followed the instructions in the repo readme to install geocoder into my project.

I get "No provider registered." this error if you done this problem please give me solution where i am wrong.

  • 写回答

1条回答 默认 最新

  • dongzouche9108 2019-06-04 11:34
    关注
    public function handle()
        {     
            $users = User::whereNull('lat')->whereNull('lng')->whereNull('city')->whereNull('state')->whereNull('address')->get();
            foreach ($users as $user)
            {
                $response = Geocode::make()->address($user->zipcode);  
                if ($response){
                    $lat     = $response->latitude();
                    $lng     = $response->longitude();
                    $city    = $response->raw()->address_components[1]->long_name;
                    $state   = $response->raw()->address_components[2]->long_name;               
                    $address = $response->formattedAddress();
                    echo  $response->locationType();
                    DB::table('users')->where('id', $user->id)->update(['lat' => $lat, 'lng' => $lng, 'city' => $city, 'state' => $state, 'address'=> $address]);
                }
            }exit;        
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用