use of com.amap.api.location.AMapLocationClientOption in project YourEyes by SevenLJY.
the class PoiSearchActivity method getDefaultOption.
/**
* 默认的定位参数
* */
private AMapLocationClientOption getDefaultOption() {
AMapLocationClientOption mOption = new AMapLocationClientOption();
//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//可选,设置是否gps优先,只在高精度模式下有效。默认关闭
mOption.setGpsFirst(true);
//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
mOption.setHttpTimeOut(30000);
//可选,设置定位间隔。默认为2秒
mOption.setInterval(2000);
//可选,设置是否返回逆地理地址信息。默认是true
mOption.setNeedAddress(true);
//可选,设置是否单次定位。默认是false
mOption.setOnceLocation(false);
//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
mOption.setOnceLocationLatest(false);
//可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);
//可选,设置是否使用传感器。默认是false
mOption.setSensorEnable(false);
//可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
mOption.setWifiScan(true);
//可选,设置是否使用缓存定位,默认为true
mOption.setLocationCacheEnable(true);
return mOption;
}
use of com.amap.api.location.AMapLocationClientOption in project YourEyes by SevenLJY.
the class LocationUtils method getDefaultOption.
//默认参数对象
private static AMapLocationClientOption getDefaultOption() {
AMapLocationClientOption mOption = new AMapLocationClientOption();
//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//可选,设置是否gps优先,只在高精度模式下有效。默认关闭
mOption.setGpsFirst(false);
//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
mOption.setHttpTimeOut(15000);
//可选,设置定位间隔。默认为2秒
mOption.setInterval(2000);
//可选,设置是否返回逆地理地址信息。默认是true
mOption.setNeedAddress(true);
//可选,设置是否单次定位。默认是false
mOption.setOnceLocation(false);
//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
mOption.setOnceLocationLatest(false);
//可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);
//可选,设置是否使用传感器。默认是false
mOption.setSensorEnable(false);
//可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
mOption.setWifiScan(true);
//可选,设置是否使用缓存定位,默认为true
mOption.setLocationCacheEnable(true);
return mOption;
}
use of com.amap.api.location.AMapLocationClientOption in project CustomViews by AndroidStudy233.
the class MainActivity method initLocation.
private void initLocation() {
/*
注意这只是个测试,没有做6.0系统的兼容.6.0以下是没问题的
*/
mLocationClient = new AMapLocationClient(this);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
// 设置只定位一次
option.setOnceLocation(true);
// 设置返回地址信息
option.setNeedAddress(true);
// option.setInterval(20000);// 设置定位间隔,默认为2000ms,最低1000ms。
mLocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
String city = aMapLocation.getCity();
String district = aMapLocation.getDistrict();
MyLogUtil.debug("高德city: " + city);
MyLogUtil.debug("高德district: " + district);
} else {
// 定位失败
MyLogUtil.error("高德Error, ErrCode:" + aMapLocation.getErrorCode() + ", errInfo:" + aMapLocation.getErrorInfo());
}
}
}
});
mLocationClient.setLocationOption(option);
mLocationClient.startLocation();
}
use of com.amap.api.location.AMapLocationClientOption in project Collar by CodeZsx.
the class PostActivity method startLocation.
private void startLocation() {
requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE);
mBinding.tvAddress.setText("定位中...");
AMapLocationListener mLocationListener = new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
Message message = new Message();
message.what = MESSAGE_LOCATION_RESULT;
message.obj = aMapLocation.getAddress();
mHandler.sendMessage(message);
} else {
// 定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
Log.e("AmapError", "location Error, ErrCode:" + aMapLocation.getErrorCode() + ", errInfo:" + aMapLocation.getErrorInfo());
}
}
}
};
mLocationClient = new AMapLocationClient(getApplicationContext());
mLocationClient.setLocationListener(mLocationListener);
// 初始化AMapLocationClientOption对象
AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
// 设置高精度定位模式:会同时使用网络定位和GPS定位,优先返回最高精度的定位结果,以及对应的地址描述信息
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
// //设置低功耗定位模式:不会使用GPS和其他传感器,只会使用网络定位(WIFI和基站定位)
// mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
// //设置仅用设备定位模式:不需要连接网络,只使用GPS进行定位,这种模式下不支持室内环境的定位,自v2.9.0版本支持返回地址描述信息
// mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Device_Sensors);
// 设置获取3s内精度最高的一次定位结果
mLocationOption.setOnceLocationLatest(true);
// 设置是否返回地址信息,默认返回地址信息
mLocationOption.setNeedAddress(true);
// 给定位客户端对象设置定位参数
mLocationClient.setLocationOption(mLocationOption);
// 启动定位
mLocationClient.startLocation();
}
use of com.amap.api.location.AMapLocationClientOption in project SmartMesh_Android by SmartMeshFoundation.
the class LoadDataService method getDefaultOption.
/**
* The default location parameters
*/
private AMapLocationClientOption getDefaultOption() {
AMapLocationClientOption mOption = new AMapLocationClientOption();
// Optional, set positioning mode, the optional model has high precision, only equipment, network only.For high precision mode by default
mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
// Optional, set whether GPS priority, only under the mode of high precision effectively.Off by default
mOption.setGpsFirst(false);
// Optional, set up the network request timeout.The default for 30 seconds.Under the mode of equipment only is invalid
mOption.setHttpTimeOut(30000);
// Optional, establishment of intervals.The default to 2 seconds,
mOption.setInterval(2000);
// Optional, whether return inverse geographical address information.The default is true
mOption.setNeedAddress(true);
// Optional, setting is a single location.The default is false
mOption.setOnceLocation(false);
// Optional Settings are waiting for the wifi refresh, the default is false. If set to true, will automatically into a single location, don't use continuous positioning
mOption.setOnceLocationLatest(false);
// Optional, set up the network protocol requests.Optional HTTP or HTTPS.The default for HTTP
AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);
// Optional, set whether to use sensors.The default is false
mOption.setSensorEnable(false);
return mOption;
}
Aggregations