高德开放平台matlab,示例中心

使用场景

该示例主要展示在同一个移动端页面内通过连续定位持续确定设备位置的同时,用户通过按钮(或其他)主动获取一次当前位置的场景。

用到产品

核心类/接口

类接口说明版本

AMapLocationClientOptionsetOnceLocation(Boolean b);设置单次定位接口V2.0.0版本起

setInterval(long time);设置连续定位时间间隔V2.0.0版本起

AMapLocationClientstartLocation();启动定位V2.0.0版本起

setLocationOption(mLocationOption);给定位客户端设置参数V2.0.0版本起

AMapLocationListeneronLocationChanged(AMapLocation amapLocation);监听器回调方法V2.0.0版本起

核心难点

分别创建单次、连续定位客户端以及监听器,这样可以有效的区分定位结果是来自持续定位还是来自单次定位。

1、分别创建定位客户端:

创建单次定位客户端:

AMapLocationClient locationClientSingle = new AMapLocationClient(this.getApplicationContext());

创建连续定位客户端:

AMapLocationClient locationClientContinue = new AMapLocationClient(this.getApplicationContext());

2、分别创建定位结果监听器:

单次定位的监听:

/**

* 单次客户端的定位监听

*/

AMapLocationListener locationSingleListener = new AMapLocationListener() {

@Override

public void onLocationChanged(AMapLocation location) {

}

};

locationClientSingle.setLocationListener(locationSingleListener);

连续定位的监听:

/**

* 连续客户端的定位监听

*/

AMapLocationListener locationContinueListener = new AMapLocationListener() {

@Override

public void onLocationChanged(AMapLocation location) {

}

};

locationClientContinue.setLocationListener(locationContinueListener);

3、分别设置定位行为:

设置单次定位的行为:

//获取一次定位结果:

//该方法默认为false。

locationClientSingleOption.setOnceLocation(true);

//关闭缓存机制

locationClientSingleOption.setLocationCacheEnable(false);

//给定位客户端对象设置定位参数

locationClientSingle.setLocationOption(locationClientSingleOption);

//启动定位

locationClientSingle.startLocation();

设置连续定位的行为:

//设置定位间隔,单位毫秒,默认为2000ms,最低1000ms。

locationClientContinueOption.setInterval(1000);

//给定位客户端对象设置定位参数

locationClientContinue.setLocationOption(locationClientContinueOption);

//启动定位

locationClientContinue.startLocation();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值