Lu Hsiang 2019-05-17 10:07 采纳率: 0%
浏览 764

有没有高手!!!可以使用百度地图API实现位置提醒的功能!!!

急求!!!可私聊!!
类似于百度地图官方给的效果图一样
自定义经纬度设置一个提醒点,提醒点半径内的圆形区域为提醒位置,自己当前位置进入提醒位置,移动设备震动
以下代码只能实现当前位置的位置提醒
/***

  • 实例演示位置提醒功能,由于定位本身具有空间性,所以设置当前点为提醒点,用户可以通过
  • 坐标拾取系统来自定义提醒点 http://api.map.baidu.com/lbsapi/getpoint/index.html
  • @author baidu
    *
    */
    public class NotifyActivity extends Activity{

    private Button startNotify;
    private Vibrator mVibrator;
    private LocationClient mLocationClient;
    private NotiftLocationListener listener;
    private double longtitude,latitude;
    private NotifyLister mNotifyLister;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView( R.layout.notify);
    listener = new NotiftLocationListener();
    mVibrator =(Vibrator)getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);

    startNotify = (Button)findViewById(R.id.notifystart);
    mLocationClient  = new LocationClient(this);
    mLocationClient.registerLocationListener(listener);
    mNotifyLister = new NotifyLister();
    mLocationClient.registerNotify(mNotifyLister);
    startNotify.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(startNotify.getText().toString().equals("开启位置提醒")){
                mLocationClient.start();
                startNotify.setText("关闭位置提醒");
            }else{
                if(mNotifyLister!=null){
                    mLocationClient.removeNotifyEvent(mNotifyLister);
                    startNotify.setText("开启位置提醒");
                }
            }
    
        }
    });
    

    }

    @Override
    protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    mLocationClient.removeNotifyEvent(mNotifyLister);
    mLocationClient.unRegisterLocationListener(listener);
    mLocationClient.stop();
    }

    @Override
    protected void onDestroy() {
    super.onDestroy();
    mLocationClient.removeNotifyEvent(mNotifyLister);
    mLocationClient.unRegisterLocationListener(listener);
    mLocationClient.stop();
    }

    @SuppressLint("HandlerLeak")
    private Handler notifyHandler = new Handler(){

    @Override
    public void handleMessage(Message msg) {
        // TODO Auto-generated method stub
        super.handleMessage(msg);
        mNotifyLister.SetNotifyLocation(latitude,longtitude, 3000,mLocationClient.getLocOption().getCoorType());//4个参数代表要位置提醒的点的坐标,具体含义依次为:纬度,经度,距离范围,坐标系类型(gcj02,gps,bd09,bd09ll)
    }
    

    };
    public class NotiftLocationListener extends BDAbstractLocationListener {

    @Override
    public void onReceiveLocation(BDLocation location) {
        //Receive Location
        longtitude = location.getLongitude();
        latitude = location.getLatitude();
        notifyHandler.sendEmptyMessage(0);
    }
    

    }
    public class NotifyLister extends BDNotifyListener{
    public void onNotify(BDLocation mlocation, float distance){
    mVibrator.vibrate(1000);//振动提醒已到设定位置附近
    Toast.makeText(NotifyActivity.this, "震动提醒", Toast.LENGTH_SHORT).show();
    }
    }
    }


  • 写回答

1条回答 默认 最新

  • ??�???18120082008 2020-02-09 15:00
    关注

    苹果手机可以,就是位置提醒,在《提醒事项》--《在指定位置提醒我》,就目前实测,只有这个好用,安卓目前没有发现哪个手机好用,华为有这个功能,但是半径太小,而且,经常失灵,如果有哪位大神有好的安卓app或者手机推荐,也告诉我一下,感谢!

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)