(未显示1个用户的3个中间版本) | |||
第1行: | 第1行: | ||
− | <div id="examples_center"> | + | <div id="examples_center"><!-- 页面标题 --><div class="title-hd">全球定位(单次/连续)</div><!-- 标题下子标题及简介,可有多个 --><div class="title-mi">功能场景</div><div class="wrap-mi">本示例展示了在设备连续定位的同时,用户通过操作界面主动获取一次当前位置的场景,例如外勤人员在外业过程中到达某一地点时进行打卡。基于百度地图全球定位服务,这一功能在国内外都可适用。</div><!-- --></div><div class="demos_wrap"><div class="header"><div class="andiord-header active">Android</div><div class="ios-header">iOS</div></div><div class="andiord-wrap wrap"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-and"></div><div class="phone-android"><div class="video-wrap infor"><div class="video-control"></div><!-- 安卓视频位置 (不写协议)--><pre>//mapopen-website-wiki.bj.bcebos.com/demos/全球定位.mov</pre> |
− | + | </div><div class="video-icon-and"><div class="play play-and"></div><div class="stop stop-and"></div></div></div><div class="progressWrap-hide-and"></div><div id="videoControls-and"><div id="progressWrap-and"><div id="playProgress-and"></div></div></div></div><div class="left-qrCode"><!-- 安卓二维码位置 --><div class="qrCode-and">1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/newqrcodes/全球定位.png</div><div>扫码体验</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><!-- 安卓使用产品下选项,可有多个 --><div class="documentA">Android定位SDK|/index.php?title=android-locsdk</div><div>></div><div class="documentA">全球定位|/index.php?title=android-locsdk/guide/get-location/latlng</div></div></div><div class="wrap_right_nav_r">下载源码</div><!-- 安卓源码地址 --><div class="github-url-and">//mapopen-website-wiki.bj.bcebos.com/demos/location/one_continuous_location.zip</div></div><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">LocationClientOption</div></div><div><div>setOnceLocation(boolean isOnceLocation)</div></div><div><div>设置是否进行单次定位,单次定位时调用start之后会默认返回一次定位结果</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">LocationClientOption</div></div><div><div>setScanSpan(int scanSpan)</div></div><div><div>连续定位时间间隔,单位是毫秒 当<1000(1s)时,定时定位无效</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">LocationClient</div></div><div><div>start()</div></div><div><div>启动定位sdk</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">LocationClient</div></div><div><div>setLocOption(LocationClientOption locOption)</div></div><div><div>给定位客户端设置参数</div></div></div></div></div></div></div></div><div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-nav"><div>1.分别创建定位客户端</div></div><div class="pre-nav" style="margin-left:10px"><div>创建单次定位客户端:</div></div><div class="pre-nav" style="margin-left:10px"><div>LocationClient locClientOne = new LocationClient(this);</div></div><div class="pre-nav" style="margin-left:10px"><div>创建多次定位客户端:</div></div><div class="pre-nav" style="margin-left:10px"><div>LocationClient locClientContinuoue = new LocationClient(this);</div></div><div class="pre-nav"><div>2.分别创建定位结果监听器</div></div><div class="pre-nav" style="margin-left:10px"><div>创建单次定位回调结果监听</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">private BDAbstractLocationListener oneLocationListener = new BDAbstractLocationListener() { | |
− | + | ||
− | + | ||
− | + | ||
− | </div> | + | |
− | <div class="demos_wrap"> | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | private BDAbstractLocationListener oneLocationListener = new BDAbstractLocationListener() { | + | |
@Override | @Override | ||
public void onReceiveLocation(BDLocation location) { | public void onReceiveLocation(BDLocation location) { | ||
第155行: | 第7行: | ||
locClientOne.registerLocationListener(oneLocationListener); | locClientOne.registerLocationListener(oneLocationListener); | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav" style="margin-left:10px"><div>创建连续定位回调结果监听</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">private BDAbstractLocationListener continuoueLocationListener = new BDAbstractLocationListener() { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | private BDAbstractLocationListener continuoueLocationListener = new BDAbstractLocationListener() { | + | |
@Override | @Override | ||
public void onReceiveLocation(BDLocation location) { | public void onReceiveLocation(BDLocation location) { | ||
第179行: | 第14行: | ||
locClientContinuoue.registerLocationListener(continuoueLocationListener); | locClientContinuoue.registerLocationListener(continuoueLocationListener); | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>3.设置定位参数并启动定位</div></div><div class="pre-nav" style="margin-left:10px"><div>设置单次定位参数</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">LocationClientOption locationClientOption = new LocationClientOption(); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | LocationClientOption locationClientOption = new LocationClientOption(); | + | |
// 可选,设置定位模式,默认高精度 LocationMode.Hight_Accuracy:高精度; | // 可选,设置定位模式,默认高精度 LocationMode.Hight_Accuracy:高精度; | ||
locationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); | locationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); | ||
第209行: | 第24行: | ||
locClientOne.start(); | locClientOne.start(); | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav" style="margin-left:10px"><div>设置连续定位参数</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">LocationClientOption locationClientOption = new LocationClientOption(); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | LocationClientOption locationClientOption = new LocationClientOption(); | + | |
// 如果设置为0,则代表单次定位,即仅定位一次,默认为0 | // 如果设置为0,则代表单次定位,即仅定位一次,默认为0 | ||
// 如果设置非0,需设置1000ms以上才有效 | // 如果设置非0,需设置1000ms以上才有效 | ||
第235行: | 第33行: | ||
locClientContinuoue.start(); | locClientContinuoue.start(); | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><!-- <div class="more-nav"> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
<div class="left-icon"></div> | <div class="left-icon"></div> | ||
<div>更多功能</div> | <div>更多功能</div> | ||
第260行: | 第50行: | ||
<div class="documentA">添加文字和信息窗|/index.php?title=test</div> | <div class="documentA">添加文字和信息窗|/index.php?title=test</div> | ||
</div> | </div> | ||
− | </div> --> | + | </div> --></div><div class="ios-wrap wrap" style="display: none;"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-ios"></div><div class="phone-ios"><div class="video-wrap infor"><div class="video-control"></div><!-- ios视频位置 --><pre>//mapopen-website-wiki.bj.bcebos.com/demos/iosVideos/location/全球定位@1x.mp4</pre> |
− | + | </div><div class="video-icon-ios"><div class="play play-ios"></div><div class="stop stop-ios"></div></div></div><div class="progressWrap-hide-ios"></div><div id="videoControls-ios"><div id="progressWrap-ios"><div id="playProgress-ios"></div></div></div></div><div class="left-qrCode iosqrCode"><!-- ios二维码位置 --><div class="qrCode-ios">1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/ioscodes/全球定位@1xios.png</div><div>扫码体验</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><!-- IOS使用产品下选项,可有多个 --><div class="documentA">iOS定位SDK|/index.php?title=ios-locsdk</div><!-- --></div></div><div class="wrap_right_nav_r">下载源码</div><!-- IOS源码地址 --><div class="github-url-ios">//mapopen-website-wiki.bj.bcebos.com/demos/location/one_continuous_locationSDK.zip</div></div><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- ios表格接口内容,可有多个 --><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">BMKLocationManager</div></div><div><div>-(BOOL)requestLocationWithReGeocode:(BOOL)withReGeocode withNetworkState:(BOOL)withNetWorkState completionBlock:(BMKLocatingCompletionBlock _Nonnull)completionBlock;</div></div><div><div>单次定位请求,定位结果通过Block回调。<br/>如果当前正在连续定位,调用此方法将会失败,返回NO</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">BMKLocationManager</div></div><div><div>- (void)startUpdatingLocation;</div></div><div><div>开始连续定位</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKLocationManager</div></div><div><div>- (void)stopUpdatingLocation;</div></div><div><div>停止连续定位</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKLocationManager</div></div><div><div>-(void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager didUpdateLocation:(BMKLocation * _Nullable)location orError:(NSError * _Nullable)error;</div></div><div><div>连续定位回调代理方法</div></div></div></div></div></div></div></div><div class="pre-nav"><div class="left-icon"></div><div>重点关注</div></div><div class="pre-nav" style="margin-left: 10px;"><div>分别创建单次、连续定位管理类,这样可以有效的区分定位结果是来自持续定位还是来自单次定位。</div></div><div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-nav"><div>1.分别创建定位管理类</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">// 创建单次定位管理类: | |
− | + | _coldLocationManager = [[BMKLocationManager alloc] init]; | |
− | + | // 创建连续定位管理类: | |
− | + | _hotLocationManager = [[BMKLocationManager alloc] init]; | |
− | + | ||
− | + | </pre> | |
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>2.配置定位管理类属性参数,设置代理</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">_coldLocationManager = [[BMKLocationManager alloc] init]; | |
− | + | // 设置返回位置的坐标系类型 | |
− | + | _coldLocationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL; | |
− | + | // 设置距离过滤参数 | |
− | + | _coldLocationManager.distanceFilter = kCLDistanceFilterNone; | |
− | + | // 设置预期精度参数 | |
− | + | _coldLocationManager.desiredAccuracy = kCLLocationAccuracyBest; | |
− | + | // 设置应用位置类型 | |
− | + | _coldLocationManager.activityType = CLActivityTypeAutomotiveNavigation; | |
− | + | // 设置是否自动停止位置更新 | |
− | + | _coldLocationManager.pausesLocationUpdatesAutomatically = NO; | |
− | + | // 设置位置获取超时时间 | |
− | + | _coldLocationManager.locationTimeout = 10; | |
− | + | // 设置获取地址信息超时时间 | |
− | + | _coldLocationManager.reGeocodeTimeout = 10; | |
− | + | // 设置delegate | |
− | + | _coldLocationManager.delegate = self; | |
− | + | ||
− | + | </pre> | |
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>3.开始定位</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">// 开始单次定位 | |
− | + | [self.coldLocationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) { | |
− | + | // 定位失败返回错误信息 | |
− | + | if (error) { | |
− | + | NSLog(@"locError:{%zd -%@};", error.code, error.localizedDescription); | |
− | + | return; | |
− | + | } | |
− | + | // 定位成功返回位置信息 | |
− | + | if (location) { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | < | + | |
− | + | ||
− | + | ||
− | + | } | |
− | + | ]; | |
− | + | // 开始连续定位 | |
− | + | [self.hotLocationManager startUpdatingLocation]; | |
− | + | 连续定位结果通过BMKLocationManagerDelegate代理方法返回 | |
− | + | /// 连续定位回调函数 | |
− | + | - (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateLocation:(BMKLocation *)location orError:(NSError *)error { | |
− | + | // 定位失败返回错误信息 | |
− | + | if (error) { | |
− | + | NSLog(@"locError:{%zd -%@};", error.code, error.localizedDescription); | |
− | + | return; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | - (void) | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | // 定位成功返回位置信息 | |
− | + | if (location) { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | if ( | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | |||
} | } | ||
− | + | </pre> | |
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>4.停止连续定位。单次定位会在定位结果返回后自动停止,单次定位结果返回之前也可通过</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">-(void)stopUpdatingLocation;方法取消。 | |
− | + | [self.hotLocationManager stopUpdatingLocation]; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | - (void) | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | </pre> | |
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div></div></div> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </div> | + |
2022年2月25日 (五) 17:18的最后版本
全球定位(单次/连续)
功能场景
本示例展示了在设备连续定位的同时,用户通过操作界面主动获取一次当前位置的场景,例如外勤人员在外业过程中到达某一地点时进行打卡。基于百度地图全球定位服务,这一功能在国内外都可适用。
Android
iOS
//mapopen-website-wiki.bj.bcebos.com/demos/全球定位.mov
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/newqrcodes/全球定位.png
扫码体验
使用产品
Android定位SDK|/index.php?title=android-locsdk
>
全球定位|/index.php?title=android-locsdk/guide/get-location/latlng
下载源码
//mapopen-website-wiki.bj.bcebos.com/demos/location/one_continuous_location.zip
核心接口
类
接口
描述
LocationClientOption
setOnceLocation(boolean isOnceLocation)
设置是否进行单次定位,单次定位时调用start之后会默认返回一次定位结果
LocationClientOption
setScanSpan(int scanSpan)
连续定位时间间隔,单位是毫秒 当<1000(1s)时,定时定位无效
LocationClient
start()
启动定位sdk
LocationClient
setLocOption(LocationClientOption locOption)
给定位客户端设置参数
核心代码
1.分别创建定位客户端
创建单次定位客户端:
LocationClient locClientOne = new LocationClient(this);
创建多次定位客户端:
LocationClient locClientContinuoue = new LocationClient(this);
2.分别创建定位结果监听器
创建单次定位回调结果监听
JAVA
private BDAbstractLocationListener oneLocationListener = new BDAbstractLocationListener() { @Override public void onReceiveLocation(BDLocation location) { } } locClientOne.registerLocationListener(oneLocationListener);
复制
深色
复制成功
创建连续定位回调结果监听
JAVA
private BDAbstractLocationListener continuoueLocationListener = new BDAbstractLocationListener() { @Override public void onReceiveLocation(BDLocation location) { } } locClientContinuoue.registerLocationListener(continuoueLocationListener);
复制
深色
复制成功
3.设置定位参数并启动定位
设置单次定位参数
JAVA
LocationClientOption locationClientOption = new LocationClientOption(); // 可选,设置定位模式,默认高精度 LocationMode.Hight_Accuracy:高精度; locationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); /// 设置是否进行单次定位,单次定位时调用start之后会默认返回一次定位结果 locationClientOption.setOnceLocation(true); // 设置定位参数 locClientOne.setLocOption(locationClientOption); // 开启定位 locClientOne.start();
复制
深色
复制成功
设置连续定位参数
JAVA
LocationClientOption locationClientOption = new LocationClientOption(); // 如果设置为0,则代表单次定位,即仅定位一次,默认为0 // 如果设置非0,需设置1000ms以上才有效 locationClientOption.setScanSpan(1000); // 设置定位参数 locClientContinuoue.setLocOption(locationClientOption); // 开启定位 locClientContinuoue.start();
复制
深色
复制成功