百度地图api 实时显示 每个人的位置和头像

UserMapController.class.php


namespace Home\Controller;
use Think\Controller;
class UserMapController extends Controller {
  //实时显示活动中用户的位置接口
    public function showplace(){
        $activity_id = I('post.activity_id/d');
        $uids = M('user_join')->where(array('activity_id'=>$activity_id,'status'=>1))->field('uid')->order('id asc')->select();


        foreach ($uids as $value) {
            $user_map = M('user_map')->where(array('uid'=>$value['uid']))->field('lng,lat')->find();
            if(!empty($user_map)){
                $position[] = $user_map;
                $headimgurl = M('user')->where(array('id'=>$value['uid']))->getField('headimgurl');
                $images[] = '/Uploads/headimg/'.$headimgurl.'_small.jpg';
            }
        }


        //加上管家图标
        $activity = M('activity')->where(array('id'=>$activity_id))->field('manager_id')->find();
        $position[count($position)] = M('user_map')->where(array('uid'=>$activity['manager_id']))->field('lng,lat')->find();
        $images[count($images)] = '/Public/images/manager.jpg';


        // $position[count($position)] = M('activity_address')->where(array('id'=>$activity['address_id']))->field('lat,lng')->find();
        // $images[count($images)] = '/Public/images/logo.jpg';


        foreach ($position as $value) {
            if($value){
                $arr[] = array_values($value);
            }
        }
        
        $pos_json = json_encode($arr);
        $img_json = json_encode($images);
        $data['pos'] = $pos_json;
        $data['img'] = $img_json;
        $this->ajaxreturn($data);
    }


    //用户地理位置信息
    public function place(){
        $activity_id = I('activity_id/d');
        $activity = M('activity')->where(array('id'=>$activity_id))->field('address_id')->find();
        $position = M('activity_address')->where(array('id'=>$activity['address_id']))->field('lat,lng,address_name')->find();
        $this->assign('position',$position);
        $this->assign('activity_id',$activity_id);
        $this->display();
    }
}



place.html






   
   
   
   
   
    xxxx


   








你可能感兴趣的:(php,ThinkPHP,3.23)