本文整理匯總了Java中com.amap.api.location.AMapLocationClient.setLocationListener方法的典型用法代碼示例。如果您正苦於以下問題:Java AMapLocationClient.setLocationListener方法的具體用法?Java AMapLocationClient.setLocationListener怎麽用?Java AMapLocationClient.setLocationListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amap.api.location.AMapLocationClient
的用法示例。
在下文中一共展示了AMapLocationClient.setLocationListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initLocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的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: startLoaction
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
/**
* 開始定位
*/
private void startLoaction() {
//初始化定位
mLocationClient = new AMapLocationClient(getActivity());
//設置定位回調監聽
mLocationClient.setLocationListener(this);
mLocationOption = new AMapLocationClientOption();
//設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
//設置是否返回地址信息(默認返回地址信息)
mLocationOption.setNeedAddress(true);
//設置是否隻定位一次,默認為false
mLocationOption.setOnceLocation(false);
//設置是否強製刷新WIFI,默認為強製刷新
mLocationOption.setWifiActiveScan(true);
//設置是否允許模擬位置,默認為false,不允許模擬位置
mLocationOption.setMockEnable(false);
//設置定位間隔 單位毫秒
mLocationOption.setInterval(100 * 1000 * 60 * 60);
//給定位客戶端對象設置定位參數
mLocationClient.setLocationOption(mLocationOption);
//啟動定位
mLocationClient.startLocation();
//顯示定位中
SnackBarUtil.showSnackBar(R.string.locating, mSwipeRefreshLayout, getActivity());
}
示例3: initLocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
/**
* 初始化高德地圖定位參數
*/
private void initLocation() {
mLocationClient=new AMapLocationClient(getApplicationContext());
mLocationClient.setLocationListener(mLocationListener);
//初始化定位參數
mLocationOption = new AMapLocationClientOption();
//設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//設置是否返回地址信息(默認返回地址信息)
mLocationOption.setNeedAddress(true);
//設置是否隻定位一次,默認為false
mLocationOption.setOnceLocation(false);
//設置是否強製刷新WIFI,默認為強製刷新
mLocationOption.setWifiScan(true);
//設置是否允許模擬位置,默認為false,不允許模擬位置
mLocationOption.setMockEnable(false);
//設置定位間隔,單位毫秒,默認為2000ms
mLocationOption.setInterval(2000);
//給定位客戶端對象設置定位參數
mLocationClient.setLocationOption(mLocationOption);
// 啟動定位
mLocationClient.startLocation();
}
示例4: initLocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的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();
}
示例5: onCreate
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
CrashReport.initCrashReport(getApplicationContext(), "9da27d3d6b", false);
initOSS();
//初始化定位
mLocationClient = new AMapLocationClient(getApplicationContext());
//設置定位回調監聽
mLocationClient.setLocationListener(mLocationListener);
mLocationOption = new AMapLocationClientOption();
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
mLocationOption.setMockEnable(false);
mLocationClient.setLocationOption(mLocationOption);
mLocationClient.startLocation();
}
示例6: initLocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
/**
* 定位初始化
*/
private void initLocation() {
//初始化定位
mLocationClient = new AMapLocationClient(mContext);
//設置定位回調監聽
mLocationClient.setLocationListener(this);
mLocationOption = new AMapLocationClientOption();
//設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//設置是否返回地址信息(默認返回地址信息)
mLocationOption.setNeedAddress(true);
//設置是否隻定位一次,默認為false
mLocationOption.setOnceLocation(false);
//設置是否強製刷新WIFI,默認為強製刷新
mLocationOption.setWifiActiveScan(true);
//設置是否允許模擬位置,默認為false,不允許模擬位置
mLocationOption.setMockEnable(false);
//設置定位間隔 單位毫秒
mLocationOption.setInterval(100 * 1000 * 60 * 60);
//給定位客戶端對象設置定位參數
mLocationClient.setLocationOption(mLocationOption);
//關閉緩存機製
mLocationOption.setLocationCacheEnable(false);
//啟動定位
mLocationClient.startLocation();
}
示例7: initLocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
private void initLocation() {
//初始化定位
mLocationClient = new AMapLocationClient(getApplicationContext());
//設置定位回調監聽
mLocationClient.setLocationListener(mLocationListener);
//初始化AMapLocationClientOption對象
mLocationOption = new AMapLocationClientOption();
//高精度定位
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//獲取一次定位結果
mLocationOption.setOnceLocation(true);
//獲取最近3s內精度最高的一次定位結果:
mLocationOption.setOnceLocationLatest(true);
mLocationClient.setLocationOption(mLocationOption);
mLocationClient.startLocation();
}
示例8: start
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
@Override
public void start() {
if (ServiceCheck.isServiceWork(mView.getViewContext(), RecordDBService.RecordDBServiceName)) {
mView.showToast("記錄服務已經啟動,請先關閉已經啟動的記錄");
}
mStoreDbRecord = new StoreDbRecord();
//region 定位配置
mLocationClient = new AMapLocationClient(mView.getViewContext());
//初始化定位參數
AMapLocationClientOption locationOption = new AMapLocationClientOption();
//設置定位監聽
mLocationClient.setLocationListener(this);
//設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式
locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//設置定位間隔,單位毫秒,默認為2000ms
locationOption.setInterval(2000);
//設置定位參數
mLocationClient.setLocationOption(locationOption);
//endregion
}
示例9: initAccuracyLocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的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);
}
示例10: initLocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
private void initLocation() {
mLocationClient = new AMapLocationClient(mView.getContext().getApplicationContext());
mLocationClientOption = new AMapLocationClientOption();
//設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式
mLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//設置是否返回地址信息(默認返回地址信息)
mLocationClientOption.setNeedAddress(true);
//設置是否隻定位一次,默認為false
mLocationClientOption.setOnceLocation(false);
//設置是否強製刷新WIFI,默認為強製刷新
mLocationClientOption.setWifiActiveScan(true);
//設置是否允許模擬位置,默認為false,不允許模擬位置
mLocationClientOption.setMockEnable(true);
//設置定位間隔,單位毫秒,默認為2000ms
mLocationClientOption.setInterval(1000);
mLocationClient.setLocationOption(mLocationClientOption);
mLocationClient.setLocationListener(this);
}
示例11: initlocation
import com.amap.api.location.AMapLocationClient; //導入方法依賴的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();
}
示例12: onCreate
import com.amap.api.location.AMapLocationClient; //導入方法依賴的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();
}
示例13: setUpListener
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
/**
* 設置監聽
*/
private void setUpListener() {
titleLeftImv.setOnClickListener(this);
currentAreaRout.setOnClickListener(this);
fullAreaRout.setOnClickListener(this);
// 添加change事件
mViewProvince.addChangingListener(this);
// 添加change事件
mViewCity.addChangingListener(this);
// 添加change事件
mViewDistrict.addChangingListener(this);
// 添加onclick事件
mConfirmTv.setOnClickListener(this);
// 設置高德地圖
aMapLocationClient = new AMapLocationClient(this.getApplicationContext());
aMapLocationClientOption = new AMapLocationClientOption();
aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
aMapLocationClientOption.setOnceLocation(true);
aMapLocationClient.setLocationListener(this);
}
示例14: initLoc
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
private void initLoc() {
//初始化定位
mLocationClient = new AMapLocationClient(getApplicationContext());
//設置定位回調監聽
mLocationClient.setLocationListener(this);
//初始化定位參數
mLocationOption = new AMapLocationClientOption();
//設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//設置是否返回地址信息(默認返回地址信息)
mLocationOption.setNeedAddress(true);
//設置是否隻定位一次,默認為false
mLocationOption.setOnceLocation(true);
//設置是否強製刷新WIFI,默認為強製刷新
mLocationOption.setWifiActiveScan(true);
//設置是否允許模擬位置,默認為false,不允許模擬位置
mLocationOption.setMockEnable(false);
//設置定位間隔,單位毫秒,默認為2000ms
mLocationOption.setInterval(2000);
//給定位客戶端對象設置定位參數
mLocationClient.setLocationOption(mLocationOption);
//啟動定位
mLocationClient.startLocation();
}
示例15: location
import com.amap.api.location.AMapLocationClient; //導入方法依賴的package包/類
/**
* 高德定位
*/
private void location() {
//初始化定位
mLocationClient = new AMapLocationClient(getApplicationContext());
//設置定位回調監聽
mLocationClient.setLocationListener(this);
mLocationOption = new AMapLocationClientOption();
//設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
//設置是否返回地址信息(默認返回地址信息)
mLocationOption.setNeedAddress(true);
//設置是否隻定位一次,默認為false
mLocationOption.setOnceLocation(false);
//設置是否強製刷新WIFI,默認為強製刷新
mLocationOption.setWifiActiveScan(true);
//設置是否允許模擬位置,默認為false,不允許模擬位置
mLocationOption.setMockEnable(false);
//設置定位間隔 單位毫秒
mLocationOption.setInterval((mSetting.getInt(Setting.AUTO_UPDATE, 3) * Setting.ONE_HOUR * 1000));
//給定位客戶端對象設置定位參數
mLocationClient.setLocationOption(mLocationOption);
//啟動定位
mLocationClient.startLocation();
}