registerclassLocationListener为什么自动定位

[android]无法从 LocationListener 获取当前所在的位置
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.
我有LocationService开始的 onResume() MainActivity和停止的 onDestroy() 。
protected void onResume() {
super.onResume();
//Start the service using alaram manager
//If its not running currently
if (isLocationServiceRunning(this)) {
am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, LocationService.class);
pi = PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(pi);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(), 1 * 60 * 1000, pi);
protected void onDestroy() {
super.onDestroy();
if (isLocationServiceRunning(this)) {
stopService(new Intent(this, LocationService.class));
if (am != null && pi != null) {
am.cancel(pi);
LocationService.java
public class LocationService extends Service implements LocationListener {
public static double curLat = 0.0;
public static double curLng = 0.0;
private LocationM
private Location currentBestL
private static final int TWO_MINUTES = 1000 * 60 * 2;
public IBinder onBind(Intent arg0) {
public int onStartCommand(Intent intent, int flags, int startId) {
mgr = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean gps_enabled = mgr
.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (gps_enabled) {
// If GPS is enabled, set criteria as ACCURACY_FINE
// and get the best provider(which usually will be GPS_PROVIDER)
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
best = mgr.getBestProvider(criteria, true);
// getLastKnownLocation so that user don't need to wait
location = mgr.getLastKnownLocation(best);
if (location == null) {
// request for a single update, and try again.
// Later will request for updates every 10 mins
mgr.requestSingleUpdate(criteria, this, null);
location = mgr
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
// If the GPS gives a location, update curLat and curLng
dumpLocation(location);
// If the location is still null, go for NETWORK_PROVIDER
best = LocationManager.NETWORK_PROVIDER;
location = mgr.getLastKnownLocation(best);
if (location != null) {
// If the NETWORK gives a location, update curLat and curLng
dumpLocation(location);
// Register the Location Manager for updates, with both the
// providers
// Since GPS updates are expensive, we ask update every 10 mins and
// unregister updates if GPS is disabled in onProviderDisabled
// callback
mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER,
10 * 60 * 1000, 50, this);
// NETWORK_PROVIDER updates every 20 secs
mgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
20 * 1000, 0, this);
return START_NOT_STICKY;
// If GPS is disables, go with NETWORK_PROVIDER
best = LocationManager.NETWORK_PROVIDER;
location = mgr.getLastKnownLocation(best);
if (location != null) {
dumpLocation(location);
// Register NETWORK_PROVIDER for updates every 20 secs
mgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
20 * 1000, 0, this);
return START_NOT_STICKY;
private void dumpLocation(Location l) {
// Called to update the curLat and curLng.
currentBestLocation =
SimpleDateFormat s = new SimpleDateFormat("dd/MM/yyyy:hh:mm:ss",
Locale.ENGLISH);
String format = s.format(l.getTime());
Geocoder coder = new Geocoder(this);
List&Address&
Address location =
address = coder.getFromLocation(l.getLatitude(), l.getLongitude(),
location = address.get(0);
} catch (Exception e) {
Log.e("Exception while getting address", e.getMessage() + "");
curLat = l.getLatitude();
curLng = l.getLongitude();
public void onLocationChanged(Location location) {
// called when location is changed, since we registered Location
// Providers
// for updates
if (isBetterLocation(location, currentBestLocation)) {
dumpLocation(location);
Log.d("Not a Better Location", "Ignore");
public void onProviderDisabled(String provider) {
// Check if best(the currently being used provider) is not null
if (best != null) {
// if best and disabled provider are same, the remove updates
if ((provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER) && best
.equals(LocationManager.GPS_PROVIDER))
|| provider
.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)
&& best.equals(LocationManager.NETWORK_PROVIDER)) {
if (mgr != null) {
mgr.removeUpdates(this);
public void onProviderEnabled(String provider) {
// This will be taken care in the onStartCommand where if gps_enabled
// case is used.
public void onStatusChanged(String provider, int status, Bundle extras) {
// No need to care about, because any thing like OUT_OF_SERVICE occurs,
// location being fetched will be null and such cases are handled above.
if ((provider.equals(LocationManager.GPS_PROVIDER))
&& (LocationProvider.OUT_OF_SERVICE == status)) {
if (mgr != null) {
mgr.removeUpdates(this);
public void onDestroy() {
super.onDestroy();
// triggered when we call stopService(LocationService);
// which is done in onDestroy of MainActivity
// Because LocationService must be stopped
// when application is closed to avoid data usage
if (mgr != null) {
mgr.removeUpdates(this);
protected boolean isBetterLocation(Location location,
Location currentBestLocation) {
if (currentBestLocation == null) {
// A new location is always better than no location
// Check whether the new location fix is newer or older
long timeDelta = location.getTime() - currentBestLocation.getTime();
boolean isSignificantlyNewer = timeDelta & TWO_MINUTES;
boolean isSignificantlyOlder = timeDelta & -TWO_MINUTES;
boolean isNewer = timeDelta & 0;
// If it's been more than two minutes since the current location, use
// the new location
// because the user has likely moved
if (isSignificantlyNewer) {
// If the new location is more than two minutes older, it must be
} else if (isSignificantlyOlder) {
// Check whether the new location fix is more or less accurate
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation
.getAccuracy());
boolean isLessAccurate = accuracyDelta & 0;
boolean isMoreAccurate = accuracyDelta & 0;
boolean isSignificantlyLessAccurate = accuracyDelta & 200;
// Check if the old and new location are from the same provider
boolean isFromSameProvider = isSameProvider(location.getProvider(),
currentBestLocation.getProvider());
// Not significantly newer or older, so check for Accuracy
if (isMoreAccurate) {
// If more accurate return true
} else if (isNewer && !isLessAccurate) {
// Same accuracy but newer, return true
} else if (isNewer && !isSignificantlyLessAccurate
&& isFromSameProvider) {
// Accuracy is less (not much though) but is new, so if from same
// provider return true
// Checks whether two providers are the same
private boolean isSameProvider(String provider1, String provider2) {
if (provider1 == null) {
return provider2 ==
return provider1.equals(provider2);
服务肯定启动和停止像预期的那样,我可以看到的位置细节在日志中,都很好。
如果当我移动到一个完全不同的位置 (300 英里)、 curLat和curLng的值的问题仍然是那样的老了,当我打开的应用程序。
是因为我不运行服务,当设备时,在运动中 (因为我的应用程序没有运行)?
因为当我打开某些其他应用程序像 FourSquare (其中获取正确的位置),然后重新打开我的应用程序,然后它就会显示正确的位置。
我应该做什么来正确刷新位置。
解决方法 1:
我认为你的问题是在这里
best = mgr.getBestProvider(criteria, true);
// getLastKnownLocation so that user don't need to wait
location = mgr.getLastKnownLocation(best);
if (location == null) {
// request for a single update, and try again.
// Later will request for updates every 10 mins
mgr.requestSingleUpdate(criteria, this, null);
location = mgr
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
因为以前有一个位置 location = mgr.getLastKnownLocation(best); 返回该位置没有启动提供程序 (请参阅。所以位置不是 null 和 mgr.requestSingleUpdate(criteria, this, null); 永远不会运行。
要获取最新位置数据提供程序必须启动。
所以一个更正可能是:
best = mgr.getBestProvider(criteria, true);
// getLastKnownLocation so that user don't need to wait
mgr.requestSingleUpdate(best, this, null);
location = mgr.getLastKnownLocation(best);
我还不确定,如果它的目的是,但这项服务将使用的网络供应商,甚至当 GPS 数据是可用的更准确 (由于选择 GPS 更新和数据陈旧过时的 10 分钟和 2 分钟时间。
P.S.有特定的原因您不想使用是谷歌发挥服务的一部分的 FusedLocationProvider 吗?我发现它变得更加简单,它理应针对选定最佳供应商和节约电池进行了优化。46607人阅读
Android(398)
导入库文件
在下载页面下载最新的库文件。将liblocSDK2.4.so文件拷贝到libs/armeabi目录下。将locSDK2.4.jar文件拷贝到工程根目录下,并在工程属性-&Java Build Path-&Libraries中选择“Add JARs”,选定locSDK2.4.jar,确定后返回。这样您就可以在程序中使用百度定位API了。&
设置AndroidManifest.xml
为区分2.3版本service,需要将manifest file中的 intent filter声明为com.baidu.location.service_v2.4 在application标签中声明service组件
&service android:name=&com.baidu.location.f& android:enabled=&true& android:process=&:remote& android:permission=&android.permission.BAIDU_LOCATION_SERVICE&&
&intent-filter&
&action android:name=&com.baidu.location.service_v2.4&&&/action&
&/intent-filter&&/service&
声明使用权限
&permission android:name=&android.permission.BAIDU_LOCATION_SERVICE&&&/permission&&uses-permission android:name=&android.permission.BAIDU_LOCATION_SERVICE&&&/uses-permission&&uses-permission android:name=&android.permission.ACCESS_COARSE_LOCATION&&&/uses-permission&&uses-permission android:name=&android.permission.ACCESS_FINE_LOCATION&&&/uses-permission&&uses-permission android:name=&android.permission.ACCESS_WIFI_STATE&&&/uses-permission&&uses-permission android:name=&android.permission.ACCESS_NETWORK_STATE&&&/uses-permission&&uses-permission android:name=&android.permission.CHANGE_WIFI_STATE&&&/uses-permission&&uses-permission android:name=&android.permission.READ_PHONE_STATE&&&/uses-permission&&uses-permission android:name=&android.permission.WRITE_EXTERNAL_STORAGE&&&/uses-permission&&uses-permission android:name=&android.permission.INTERNET& /&&uses-permission android:name=&android.permission.MOUNT_UNMOUNT_FILESYSTEMS&&&/uses-permission&&uses-permission android:name=&android.permission.READ_LOGS&&&/uses-permission&
import相关类
import com.baidu.location.BDLocation;import com.baidu.location.BDLocationListener;import com.baidu.location.LocationClient;import com.baidu.location.LocationClientOption;import com.baidu.location.BDNotifyListener;//假如用到位置提醒功能,需要import该类
功能类的使用
初始化LocationClient类
此处需要注意:LocationClient类必须在主线程中声明。需要Context类型的参数。
public LocationClient mLocationClient = null;public BDLocationListener myListener = new MyLocationListener();&public void onCreate() {
mLocationClient = new LocationClient(this);
//声明LocationClient类
mLocationClient.registerLocationListener( myListener );
//注册监听函数}
实现BDLocationListener接口
BDLocationListener接口有2个方法需要实现:
1.接收异步返回的定位结果,参数是BDLocation类型参数。
2.接收异步返回的POI查询结果,参数是BDLocation类型参数。
public class MyLocationListenner implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) {
if (location == null)
sb = new (256);
sb.append(&time&: &);
sb.append(location.getTime());
sb.append(&\nerror code&: &);
sb.append(location.getLocType());
sb.append(&\nlatitude&: &);
sb.append(location.getLatitude());
sb.append(&\nlontitude&: &);
sb.append(location.getLongitude());
sb.append(&\nradius&: &);
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation){
sb.append(&\nspeed&: &);
sb.append(location.getSpeed());
sb.append(&\nsatellite&: &);
sb.append(location.getSatelliteNumber());
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append(&\naddr&: &);
sb.append(location.getAddrStr());
logMsg(sb.toString()); }public void onReceivePoi(BDLocation poiLocation) {
if (poiLocation == null){
sb = new (256);
sb.append(&Poi time&: &);
sb.append(poiLocation.getTime());
sb.append(&\nerror code&: &);
sb.append(poiLocation.getLocType());
sb.append(&\nlatitude&: &);
sb.append(poiLocation.getLatitude());
sb.append(&\nlontitude&: &);
sb.append(poiLocation.getLongitude());
sb.append(&\nradius&: &);
sb.append(poiLocation.getRadius());
if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append(&\naddr&: &);
sb.append(poiLocation.getAddrStr());
if(poiLocation.hasPoi()){
sb.append(&\nPoi:&);
sb.append(poiLocation.getPoi());
sb.append(&noPoi information&);
logMsg(sb.toString());
设置定位参数包括:定位模式(单次定位,定时定位),返回坐标类型,是否打开GPS等等。eg:
LocationClientOption option = new LocationClientOption();option.setOpenGps(true);option.setAddrType(&detail&);option.setCoorType(&gcj02&);option.setScanSpan(5000);option.disableCache(true);//禁止启用缓存定位option.setPoiNumber(5); //最多返回POI个数 option.setPoiDistance(1000); //poi查询距离
option.setPoiExtraInfo(true); //是否需要POI的电话和地址等详细信息
mLocClient.setLocOption(option);
发起定位请求
发起定位请求。请求过程是异步的,定位结果在上面的监听函数onReceiveLocation中获取。
if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestLocation();else
Log.d(&LocSDK_2.0_Demo1&, &locClient is null or not started&);
发起POI查询请求
发起POI查询请求。请求过程是异步的,定位结果在上面的监听函数onReceivePoi中获取。
if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestPoi();
位置提醒使用
位置提醒最多提醒3次,3次过后将不再提醒。 假如需要再次提醒,或者要修改提醒点坐标,都可通过函数SetNotifyLocation()来实现。
//位置提醒相关代码mNotifyer = new NotifyLister();mNotifyer.SetNotifyLocation(42.37,113.6,3000,&gps&);//4个参数代表要位置提醒的点的坐标,具体含义依次为:纬度,经度,距离范围,坐标系类型(gcj02,gps,bd09,bd09ll)mLocationClient.registerNotify(mNotifyer);//注册位置提醒监听事件后,可以通过SetNotifyLocation 来修改位置提醒设置,修改后立刻生效。
//BDNotifyListner实现public class NotifyLister extends BDNotifyListener{
public void onNotify(BDLocation mlocation, float distance){ mVibrator01.vibrate(1000);//振动提醒已到设定位置附近
//取消位置提醒mLocationClient.removeNotifyEvent(mNotifyer);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:4711370次
积分:35346
积分:35346
排名:第131名
原创:21篇
转载:1092篇
评论:483条
(1)(12)(10)(13)(10)(11)(9)(3)(10)(13)(10)(3)(2)(1)(4)(5)(10)(1)(7)(13)(6)(4)(3)(9)(10)(3)(13)(6)(22)(14)(13)(19)(26)(50)(9)(12)(13)(47)(22)(31)(29)(18)(26)(12)(6)(23)(5)(12)(4)(10)(12)(79)(44)(86)(12)(9)(7)(21)(6)(10)(14)(23)(30)(4)(1)(3)(5)(3)(9)(2)(16)(3)(17)(5)(5)(8)(2)(3)(3)(20)(10)(14)(3)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test_5);
initViews();
OnClickListener clickListener = new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String keyworld = &&;// 此处要对输入进行校验
if (v.getId() == R.id.product_1) {
keyworld = PRODUCT_NAME[0];
} else if (v.getId() == R.id.product_2) {
keyworld = PRODUCT_NAME[1];
} else if (v.getId() == R.id.product_3) {
keyworld = PRODUCT_NAME[2];
} else if (v.getId() == R.id.product_4) {
keyworld = PRODUCT_NAME[3];
} else if (v.getId() == R.id.product_5) {
keyworld = PRODUCT_NAME[4];
product_1.setOnClickListener(clickListener);
product_2.setOnClickListener(clickListener);
product_3.setOnClickListener(clickListener);
product_4.setOnClickListener(clickListener);
product_5.setOnClickListener(clickListener);
locationClient.start();
if (locationClient != null && locationClient.isStarted()) {
Log.i(&start&, &location服务开始&);
locationClient.requestLocation();
Log.i(&LocSDK_2.0_Demo1&, &locClient is null or not started&);
// 发起POI查询请求。请求过程是异步的,定位结果在上面的监听函数onReceivePoi中获取。
if (locationClient != null && locationClient.isStarted())
locationClient.requestPoi();
locationData = new LocationData();
public void init() {
// 初始化application,如果BMapManager为Null,建立实例
app = (DemoApplication) this.getApplication();
Toast.makeText(Gift.this, &mBmapmanager=& + app.mBMapManager, 1).show();
if (app.mBMapManager == null) {
Toast.makeText(Gift.this, &再次初始化地图manager&, 1).show();
app.mBMapManager = new BMapManager(this);
// DemoApplication用来验证key和网络连接,用getApplication()获得BMapManager实例
app.mBMapManager.init(DemoApplication.strKey,
new DemoApplication.MyGeneralListener());
// 实例化locationClient类
locationClient = new LocationClient(getApplicationContext());
// 注册监听事件,MyLocationListener两个重写方法处理相关操作
locationClient.registerLocationListener(bdLocationListener);
// 设置定位参数包括:定位模式(单次定位,定时定位),返回坐标类型,是否打开GPS等等
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打开gps
option.setCoorType(&gcj02&);
option.setScanSpan(1000);
// 发起定位请求。请求过程是异步的,定位结果在上面的监听函数onReceiveLocation中获取。
locationClient.setLocOption(option);
locationClient.start();
请看以上代码,本人最近又开始研究百度地图定位问题,但是非常郁闷,这段代码明明以前写的时候是可以进行定位,现在却没反应,晕啊。
权限 user-permission 和 service 都加了
后来经过多方学习了解
把 locationClient = new LocationClient(this); 改成 locationClient = new LocationClient(getApplicationContext()); 就可以了。这是为什么啊。。不懂是不是和百度地图
定位sdk的版本有关,求大神解释。。
本文已收录于以下专栏:
相关文章推荐
转自:http://lszdb1983./blog/static//
导入库文件
在下载页面下载最新的库文件。...
最近在进行百度地图开发的时候,虽然百度公司的demo很好,但是还是有很多的坑的,比如就他的定位的代码,起初在demo上是可以运行的,但是移植到自己的上面的时候,总是有问题。一下我的一些经验。
百度地图sdk
locationclient.start()
mapview is null
Multiple dex files define Lcom/ac··········&#18...
前言:不畏人生,或许才能方得始终;大胆拼,大胆闯是要有一定资本的,在能力不到的时候,就只有选择忍气吞声!
相关博客:
《Android自定义控件三部曲文章索引》
:http://blog.csdn...
前言:人或许天生是懒惰的,明知道的不足,却不努力弥补。
前几篇给大家讲述了如何针对某一个控件应用动画,这篇将给大家讲解如何给容器中的控件应用统一动画。即在容器中控件出现时,不必为每个控件添加进入动画,...
如果你的程序在运行是就出现崩溃 并且报一下错误:
java.lang.UnsatisfiedLinkError: No implementation found for int com.baidu.p...
一、申请规范:来到申请key官网:点击进入申请key
可以看到申请密钥要填写四个值,
规范一、应用名称:必须和你准备使用百度地图SDK的项目名称是一模一样,允许复制粘贴进去规范二、:发布版SHA1...
Fresco 与 百度地图SDK冲突解决办法
最近项目中需要加载大图,宽750px,高度不限,但是却出现了加载大图后,图片模糊的问题,由于图片加载框架用的是UIL,然后google了一下,找...
昨天公司项目有邮件说客运站查询地理位置的时候,地图不能够展示,我安装测试了,发现不仅仅是不展示啊,
黑屏,闪退,我擦,这还得了,赶紧解决。
    于是拿代码去debug,发现,(⊙o⊙)…没问题...
进行百度地图开发时,有时候会遇到图标显示出来了,但是图层没有显示出来的情况。具体应该有下面两种情形:
         
       &...
他的最新文章
讲师:王哲涵
讲师:王渊命
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)11136人阅读
点滴积累(4)
& & & &大家去网上搜索Android定位location为null没法定位问题,估计有一大堆文章介绍如何来解决,但是最后大家发现基本没用。本文将从Android定位实现原理来深入分析没法定位原因并提出真正的解决方案。在分析之前,我们肯定得先看看android官方提供的定位SDK。
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String provider = mLocationManager.getProvider(LocationManager.GPS_PROVIDER);
Criteria crite = new Criteria();
crite.setAccuracy(Crite.ACCURACY_FINE); //精度
crite.setPowerRequirement(Crite.POWER_LOW); //功耗类型选择
String provider = mLocationManager.getBestProvider(crite, true);
&获取Location
Location location = mLocationManager.getLocation(provider);
,这是因为程序还从来没有请求 过,只需重新请求更新location,并注册监听器以接收更新后的location信息。
LocationListener locationListener = new LocationListener() {
public void onStatusChanged(String provider, int status, Bundle extras) {
public void onProviderEnabled(String provider) {
public void onProviderDisabled(String provider) {
public void onLocationChanged(Location location) {
longitude = location.getLongitude();
= location.getLatitude();
Log.d(TAG,&Location longitude:&+ longitude +& latitude: &+ latitude );
mLocationManager.requestLocationUpdates(serviceProvider, 10000, 1, this);
android:name=&com.baidu.location.f&
android:enabled=&true&
android:process=&:remote& &
&/service&
&meta-data
android:name=&com.baidu.lbsapi.API_KEY&
android:value=&xxxxx & /&
&uses-permission android:name=&android.permission.ACCESS_NETWORK_STATE& /&
&uses-permission android:name=&android.permission.ACCESS_COARSE_LOCATION& /&
&uses-permission android:name=&android.permission.ACCESS_FINE_LOCATION& /&
public class LocationUtil {
private final static boolean DEBUG =
private final static String TAG = &LocationUtil&;
private static LocationUtil mI
private BDLocation mLocation =
private MLocation
mBaseLocation = new MLocation();
public static LocationUtil getInstance(Context context) {
if (mInstance == null) {
mInstance = new LocationUtil(context);
Context mC
public BDLocationListener myListener = new MyLocationListener();
private LocationClient mLocationC
public LocationUtil(Context context) {
mLocationClient = new LocationClient(context.getApplicationContext());
initParams();
mLocationClient.registerLocationListener(myListener);
public void startMonitor() {
if (DEBUG) Log.d(TAG, &start monitor location&);
if (!mLocationClient.isStarted()) {
mLocationClient.start();
if (mLocationClient != null && mLocationClient.isStarted()) {
mLocationClient.requestLocation();
Log.d(&LocSDK3&, &locClient is null or not started&);
public void stopMonitor() {
if (DEBUG) Log.d(TAG, &stop monitor location&);
if (mLocationClient != null && mLocationClient.isStarted()) {
mLocationClient.stop();
public BDLocation getLocation() {
if (DEBUG) Log.d(TAG, &get location&);
public MLocation getBaseLocation() {
if (DEBUG) Log.d(TAG, &get location&);
return mBaseL
private void initParams() {
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);
//option.setPriority(LocationClientOption.NetWorkFirst);
option.setAddrType(&all&);//返回的定位结果包含地址信息
option.setCoorType(&bd09ll&);//返回的定位结果是百度经纬度,默认值gcj02
option.setScanSpan(5000);//设置发起定位请求的间隔时间为5000ms
option.disableCache(true);//禁止启用缓存定位
option.setPoiNumber(5);
//最多返回POI个数
option.setPoiDistance(1000); //poi查询距离
option.setPoiExtraInfo(true); //是否需要POI的电话和地址等详细信息
mLocationClient.setLocOption(option);
public class MyLocationListener implements BDLocationListener {
public void onReceiveLocation(BDLocation location) {
if (location == null) {
mLocation =
mBaseLocation.latitude = mLocation.getLatitude();
mBaseLocation.longitude = mLocation.getLongitude();
StringBuffer sb = new StringBuffer(256);
sb.append(&time : &);
sb.append(location.getTime());
sb.append(&\nerror code : &);
sb.append(location.getLocType());
sb.append(&\nlatitude : &);
sb.append(location.getLatitude());
sb.append(&\nlontitude : &);
sb.append(location.getLongitude());
sb.append(&\nradius : &);
sb.append(location.getRadius());
sb.append(&\ncity : &);
sb.append(location.getCity());
if (location.getLocType() == BDLocation.TypeGpsLocation){
sb.append(&\nspeed : &);
sb.append(location.getSpeed());
sb.append(&\nsatellite : &);
sb.append(location.getSatelliteNumber());
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append(&\naddr : &);
sb.append(location.getAddrStr());
if (DEBUG) Log.d(TAG, && + sb);
public void onReceivePoi(BDLocation poiLocation) {
public class MLocation {
/********************************
* 本文来自博客 &“爱踢门”
* 转载请标明出处:
******************************************/
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:91531次
积分:1231
积分:1231
排名:千里之外
原创:28篇
评论:70条
(3)(2)(2)(14)(9)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 misc register 的文章

 

随机推荐