本文整理汇总了Java中com.amap.api.location.AMapLocationListener类的典型用法代码示例。如果您正苦于以下问题:Java AMapLocationListener类的具体用法?Java AMapLocationListener怎么用?Java AMapLocationListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AMapLocationListener类属于com.amap.api.location包,在下文中一共展示了AMapLocationListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
private void initLocation() {
mLocationClient = new AMapLocationClient(this);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setOnceLocation(true);
mLocationClient.setLocationOption(option);
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();
String location = StringUtils.extractLocation(city, district);
mCityAdapter.updateLocateState(LocateState.SUCCESS, location);
} else {
//定位失败
mCityAdapter.updateLocateState(LocateState.FAILED, null);
}
}
}
});
}
示例2: initLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
private void initLocation() {
mLocationClient = new AMapLocationClient(this);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setOnceLocation(true);
mLocationClient.setLocationOption(option);
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();
Log.e("onLocationChanged", "city: " + city);
Log.e("onLocationChanged", "district: " + district);
String location = StringUtils.extractLocation(city, district);
mCityAdapter.updateLocateState(LocateState.SUCCESS, location);
} else {
//定位失败
mCityAdapter.updateLocateState(LocateState.FAILED, null);
}
}
}
});
mLocationClient.startLocation();
}
示例3: initlocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
/**
* 获得位置
*/
private void initlocation(){
mlocationClient = new AMapLocationClient(this);
mLocationOption = new AMapLocationClientOption();
mlocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
locaMapLocation =aMapLocation;
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
//定位成功回调信息,设置相关消息
aMapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见定位类型表
aMapLocation.getLatitude();//获取纬度
aMapLocation.getLongitude();//获取经度
aMapLocation.getAccuracy();//获取精度信息
} else {
}
}
}
});
//设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
mLocationOption.setInterval(30000);
mlocationClient.setLocationOption(mLocationOption);
mlocationClient.startLocation();
}
示例4: initAccuracyLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
public static void initAccuracyLocation(AMapLocationClient locationClient, AMapLocationListener listener) {
AMapLocationClientOption locationOption = new AMapLocationClientOption();
// 设置定位模式为高精度模式
locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//设置是否返回地址信息(默认返回地址信息)
locationOption.setNeedAddress(true);
//设置是否只定位一次,默认为false
locationOption.setOnceLocation(false);
//设置是否强制刷新WIFI,默认为强制刷新
locationOption.setWifiActiveScan(true);
//设置是否允许模拟位置,默认为false,不允许模拟位置
locationOption.setMockEnable(false);
//设置定位间隔,单位毫秒,默认为2000ms
locationOption.setInterval(2000);
//给定位客户端对象设置定位参数
locationClient.setLocationOption(locationOption);
// 设置定位监听
locationClient.setLocationListener(listener);
}
示例5: initLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
private void initLocation() {
//高德地图
mLocationClient = new AMapLocationClient(getApplicationContext());
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//高精度
option.setOnceLocation(true);
mLocationClient.setLocationOption(option);
mLocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {
String city = aMapLocation.getCity();
String district = aMapLocation.getDistrict();
LogUtil.d(TAG, "onLocationChanged: district:"+district+"CityDao:"+city);
//区分是否是县
String location = district.endsWith("县")||district.endsWith("区") ? district.substring(0, district.length() - 1) : city.substring(0, city.length() - 1);
//重置定位状态
CityDao cityDao = DBManager.getInstance().findCity(location);
if (cityDao == null) {
cityDao = DBManager.getInstance().findCity(city.substring(0, city.length() - 1));
}
if (cityDao != null) {
searchViewAdapter.updateLocateState(SearchViewAdapter.LOCATE_SUCCESS, cityDao);
} else {
searchViewAdapter.updateLocateState(SearchViewAdapter.LOCATE_FAILED, null);
}
} else {
searchViewAdapter.updateLocateState(SearchViewAdapter.LOCATE_FAILED, null);
}
searchViewAdapter.notifyItemChanged(0);
}
});
}
示例6: initLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
private void initLocation() {
mLocationClient = new AMapLocationClient(this);//初始化定位
AMapLocationClientOption option = new AMapLocationClientOption();//初始化定位参数,定位参数包括:定位模式(高精度定位模式,低功耗定位模式和仅设备定位模式),是否返回地址信息等。
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//高精度定位模式:会同时使用网络定位和GPS定位,优先返回最高精度的定位结果
option.setNeedAddress(true);//设置是否返回地址信息,默认为true
option.setOnceLocation(true);//设置是否只定位一次,默认为false
option.setMockEnable(true);//设置是否允许模拟位置,默认为false
option.setInterval(5000);//设置定位间隔,单位毫秒,默认为2000ms
mLocationClient.setLocationOption(option);
mLocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
Log.e("----", aMapLocation.toString());
if (aMapLocation.getErrorCode() == 0) {//定位成功回调信息,设置相关消息
Log.e("当前定位结果来源:", Integer.toString(aMapLocation.getLocationType()));
String city = aMapLocation.getCity();
String district = aMapLocation.getDistrict();
Log.e("城市: ", city);
Log.e("地区: ", district);
Log.e("地址", aMapLocation.getAddress());//如果option中设置isNeedAddress为false,则没有此结果,网络定位结果中会有地址信息,GPS定位不返回地址信息
String location = StringUtils.extractLocation(city, district);
mCityAdapter.updateLocateState(LocateState.SUCCESS, location);
} else {
//定位失败
mCityAdapter.updateLocateState(LocateState.FAILED, null);
Log.e("定位失败", "错误码:" + aMapLocation.getErrorCode());
}
} else {//显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。
Log.e("aMapLocation", "null");
Log.e("AmapError", "location Error, ErrCode:"
+ aMapLocation.getErrorCode() + ", errInfo:"
+ aMapLocation.getErrorInfo());
}
}
});
mLocationClient.startLocation();//启动定位
}
示例7: initLocationOptions
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
private void initLocationOptions(Context context) {
mLocationClient = new AMapLocationClient(context);
AMapLocationListener mLocationListener = new MyAMapLocationListener();
AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//设置是否返回地址信息(默认返回地址信息)
mLocationOption.setNeedAddress(true);
//单位是毫秒,默认30000毫秒,建议超时时间不要低于8000毫秒。
mLocationOption.setHttpTimeOut(20000);
mLocationOption.setOnceLocation(true);
//给定位客户端对象设置定位参数
mLocationClient.setLocationOption(mLocationOption);
mLocationClient.setLocationListener(mLocationListener);
}
示例8: startLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
public void startLocation(AMapLocationListener locationListener){
mClientOption.setLocationMode(mMode);
mClientOption.setNeedAddress(isNeedAddress);
mClientOption.setOnceLocation(isOnceLocation);
mClientOption.setWifiActiveScan(isWifiActiveScan);
mClientOption.setMockEnable(isMockEnable);
mClientOption.setInterval(interval);
mAMapLocationClient.setLocationOption(mClientOption);
mAMapLocationClient.setLocationListener(locationListener);
mAMapLocationClient.startLocation();
}
示例9: CaluteDistance
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
private void CaluteDistance() {
//定位到当前位置并且获取相应经纬度
mLocationClient = new AMapLocationClient(getActivity());
mLocationOption = new AMapLocationClientOption();
mLocationOption.setOnceLocation(true);
mLocationClient.setLocationOption(mLocationOption);
mLocationClient.startLocation();
mLocationClient.setLocationListener(new AMapLocationListener() {
@SuppressWarnings("static-access")
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (amapLocation != null) {
if (amapLocation.getErrorCode() == 0) {
latidue = amapLocation.getLatitude();//获取当前位置的纬度
longitude = amapLocation.getLongitude();//获取当前位置的经度
LatLng startLatlng = new LatLng(latidue, longitude);
Log.e("nihao",latidue+".........");
LatLng endLatlng = new LatLng(Float.valueOf(getArguments().getString("latidue").toString()), Float.valueOf(getArguments().getString("longitude").toString()));
Float distance = AMapUtils.calculateLineDistance(startLatlng, endLatlng);
//设置当前店铺大概离你多少距离
tv_distance.setText("约" + Math.round(distance) + "米");
}
}
}
});
}
示例10: gettAccuracyLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
public void gettAccuracyLocation(AMapLocationListener listener, long Interval) {
resetClientOption(false);
// 设置定位模式为高精度模式
locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//设置定位间隔,单位毫秒,默认为2000ms
locationOption.setInterval(Interval);
// 设置定位监听
getLocationClient().setLocationListener(listener);
}
示例11: gettBatterySavingLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
public void gettBatterySavingLocation(AMapLocationListener listener, long Interval) {
resetClientOption(false);
// 设置定位模式
locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
//设置定位间隔,单位毫秒,默认为2000ms
locationOption.setInterval(Interval);
// 设置定位监听
getLocationClient().setLocationListener(listener);
}
示例12: getOnceLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
public void getOnceLocation(AMapLocationListener listener) {
resetClientOption(true);
// 设置定位模式
locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
// 设置定位监听
getLocationClient().setLocationListener(listener);
getLocationClient().startLocation();
}
示例13: getLastLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
public void getLastLocation(AMapLocationListener listener){
if (getLocationClient().getLastKnownLocation() != null){
listener.onLocationChanged(getLocationClient().getLastKnownLocation());
}else{
getOnceLocation(listener);
}
}
示例14: onCreate
import com.amap.api.location.AMapLocationListener; //导入依赖的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);
}
}
}
});
}
示例15: stopLocation
import com.amap.api.location.AMapLocationListener; //导入依赖的package包/类
public void stopLocation(AMapLocationListener locationListener){
mAMapLocationClient.stopLocation();
mAMapLocationClient.unRegisterLocationListener(locationListener);
mClientOption = null;
}