本文整理汇总了Java中com.amap.api.location.AMapLocationClientOption.AMapLocationMode类的典型用法代码示例。如果您正苦于以下问题:Java AMapLocationMode类的具体用法?Java AMapLocationMode怎么用?Java AMapLocationMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AMapLocationMode类属于com.amap.api.location.AMapLocationClientOption包,在下文中一共展示了AMapLocationMode类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultOption
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; //导入依赖的package包/类
/**
* 默认的定位参数
* @since 2.8.0
* @author hongming.wang
*
*/
private AMapLocationClientOption getDefaultOption(){
AMapLocationClientOption mOption = new AMapLocationClientOption();
mOption.setLocationMode(AMapLocationMode.Hight_Accuracy);//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
mOption.setGpsFirst(false);//可选,设置是否gps优先,只在高精度模式下有效。默认关闭
mOption.setHttpTimeOut(30000);//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
mOption.setInterval(2000);//可选,设置定位间隔。默认为2秒
mOption.setNeedAddress(true);//可选,设置是否返回逆地理地址信息。默认是true
mOption.setOnceLocation(false);//可选,设置是否单次定位。默认是false
mOption.setOnceLocationLatest(false);//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
AMapLocationClientOption.setLocationProtocol(AMapLocationProtocol.HTTP);//可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
mOption.setSensorEnable(false);//可选,设置是否使用传感器。默认是false
mOption.setWifiScan(true); //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
mOption.setLocationCacheEnable(true); //可选,设置是否使用缓存定位,默认为true
return mOption;
}
示例2: onCreate
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
context = this;
initControls();
mapView.onCreate(savedInstanceState);// 此方法必须重写
locationClient = new AMapLocationClient(this.getApplicationContext());
locationOption = new AMapLocationClientOption();
// 设置定位模式为低功耗模式
locationOption.setLocationMode(AMapLocationMode.Battery_Saving);
// 设置定位监听
locationClient.setLocationListener(this);
initMap();
initData(this.getIntent().getExtras());
initActionBar();
}
示例3: getLocation
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; //导入依赖的package包/类
public void getLocation(Context context) {
locationClient = new AMapLocationClient(context);
locationOption = new AMapLocationClientOption();
locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
locationClient.setLocationListener(this);
locationOption.setOnceLocation(true);
locationClient.setLocationOption(locationOption);
locationClient.startLocation();
}
示例4: onCreate
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm_location);
setTitle(R.string.title_alarmCPU);
etInterval = (EditText) findViewById(R.id.et_interval);
etAlarm = (EditText) findViewById(R.id.et_alarm);
cbAddress = (CheckBox) findViewById(R.id.cb_needAddress);
cbGpsFirst = (CheckBox) findViewById(R.id.cb_gpsFirst);
tvReult = (TextView) findViewById(R.id.tv_result);
btLocation = (Button) findViewById(R.id.bt_location);
btLocation.setOnClickListener(this);
locationClient = new AMapLocationClient(this.getApplicationContext());
locationOption = new AMapLocationClientOption();
// 设置定位模式为高精度模式
locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
// 设置定位监听
locationClient.setLocationListener(this);
// 创建Intent对象,action为LOCATION
alarmIntent = new Intent();
alarmIntent.setAction("LOCATION");
IntentFilter ift = new IntentFilter();
// 定义一个PendingIntent对象,PendingIntent.getBroadcast包含了sendBroadcast的动作。
// 也就是发送了action 为"LOCATION"的intent
alarmPi = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
// AlarmManager对象,注意这里并不是new一个对象,Alarmmanager为系统级服务
alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
//动态注册一个广播
IntentFilter filter = new IntentFilter();
filter.addAction("LOCATION");
registerReceiver(alarmReceiver, filter);
}
示例5: setLocationOption
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; //导入依赖的package包/类
private void setLocationOption() {
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode(AMapLocationMode.Hight_Accuracy);
option.setNeedAddress(true);
this.mLocationClient.setLocationOption(option);
}
示例6: onCreate
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geofence_old);
setTitle(R.string.oldGeoFence);
etRadius = (EditText) findViewById(R.id.et_radius);
cbAlertIn = (CheckBox) findViewById(R.id.cb_alertIn);
cbAlertOut = (CheckBox) findViewById(R.id.cb_alertOut);
tvReult = (TextView) findViewById(R.id.tv_result);
btFence = (Button) findViewById(R.id.bt_fence);
btFence.setOnClickListener(this);
IntentFilter fliter = new IntentFilter(
ConnectivityManager.CONNECTIVITY_ACTION);
fliter.addAction(GEOFENCE_BROADCAST_ACTION);
registerReceiver(mGeoFenceReceiver, fliter);
Intent intent = new Intent(GEOFENCE_BROADCAST_ACTION);
mPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
intent, 0);
onceClient = new AMapLocationClient(getApplicationContext());
locationClient = new AMapLocationClient(this.getApplicationContext());
locationOption = new AMapLocationClientOption();
// 设置定位模式高精度,添加地理围栏最好设置成高精度模式
locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
// 设置定位监听
locationClient.setLocationListener(this);
AMapLocationClientOption onceOption = new AMapLocationClientOption();
onceOption.setOnceLocation(true);
onceClient.setLocationOption(onceOption);
onceClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation loc) {
if (loc != null) {
if (loc.getErrorCode() == 0) {
if (null != locationClient) {
float radius = 1000;
String strRadius = etRadius.getText().toString();
if (!TextUtils.isEmpty(strRadius)) {
radius = Float.valueOf(strRadius);
}
// 添加地理围栏,
// 第一个参数:围栏ID,可以自定义ID,示例中为了方便只使用一个ID;第二个:纬度;第三个:精度;
// 第四个:半径;第五个:过期时间,单位毫秒,-1代表不过期;第六个:接收触发消息的PendingIntent
locationClient.addGeoFenceAlert("fenceId",
loc.getLatitude(), loc.getLongitude(),
radius, -1, mPendingIntent);
}
} else {
Toast.makeText(getApplicationContext(), "获取当前位置失败!",
Toast.LENGTH_SHORT).show();
Message msg = mHandler.obtainMessage();
msg.obj = loc;
msg.what = -1;
mHandler.sendMessage(msg);
}
}
}
});
}
示例7: startLocation
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; //导入依赖的package包/类
@ReactMethod
public void startLocation(@Nullable ReadableMap options) {
this.mLocationClient.startLocation();
AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
// 默认值
needMars = false;
needDetail = false;
if (options != null) {
if (options.hasKey("needMars")) {
needMars = options.getBoolean("needMars");
}
if (options.hasKey("needDetail")) {
needDetail = options.getBoolean("needDetail");
}
if (options.hasKey("accuracy")) {
//设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
switch(options.getString("accuracy")) {
case "BatterySaving":
mLocationOption.setLocationMode(AMapLocationMode.Battery_Saving);
break;
case "DeviceSensors":
mLocationOption.setLocationMode(AMapLocationMode.Device_Sensors);
break;
case "HighAccuracy":
mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
break;
default:
break;
}
}
if (options.hasKey("needAddress")) {
//设置是否返回地址信息(默认返回地址信息)
mLocationOption.setNeedAddress(options.getBoolean("needAddress"));
}
if (options.hasKey("onceLocation")) {
//设置是否只定位一次,默认为false
mLocationOption.setOnceLocation(options.getBoolean("onceLocation"));
}
if (options.hasKey("wifiActiveScan")) {
//设置是否强制刷新WIFI,默认为强制刷新
//模式为仅设备模式(Device_Sensors)时无效
mLocationOption.setWifiActiveScan(options.getBoolean("wifiActiveScan"));
}
if (options.hasKey("mockEnable")) {
//设置是否允许模拟位置,默认为false,不允许模拟位置
//模式为低功耗模式(Battery_Saving)时无效
mLocationOption.setMockEnable(options.getBoolean("mockEnable"));
}
if (options.hasKey("interval")) {
//设置定位间隔,单位毫秒,默认为2000ms
mLocationOption.setInterval(options.getInt("interval"));
}
if (options.hasKey("killProcess")) {
//设置退出时是否杀死service
//默认值:false, 不杀死
//模式为仅设备模式(Device_Sensors)时无效
mLocationOption.setKillProcess(options.getBoolean("killProcess"));
}
if (options.hasKey("httpTimeOut")) {
//设置联网超时时间
//默认值:30000毫秒
//模式为仅设备模式(Device_Sensors)时无效
mLocationOption.setHttpTimeOut(options.getInt("httpTimeOut"));
}
}
//给定位客户端对象设置定位参数
this.mLocationClient.setLocationOption(mLocationOption);
//启动定位
this.mLocationClient.startLocation();
}