當前位置: 首頁>>代碼示例>>Java>>正文


Java AMapLocationListener類代碼示例

本文整理匯總了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);
                }
            }
        }
    });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:CityPickerActivity.java

示例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();
}
 
開發者ID:jacksenh,項目名稱:CitySelct,代碼行數:27,代碼來源:CityPickerActivity.java

示例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();
    }
 
開發者ID:yun2win,項目名稱:yun2win-sdk-android,代碼行數:29,代碼來源:AppContext.java

示例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);
    }
 
開發者ID:joy-inc,項目名稱:joy-app,代碼行數:21,代碼來源:MapUtil.java

示例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);
        }
    });
}
 
開發者ID:YugengWang,項目名稱:OneWeather,代碼行數:36,代碼來源:SearchActivity.java

示例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();//啟動定位
}
 
開發者ID:shenhuanet,項目名稱:AndroidOpen,代碼行數:39,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:lzcmagic,項目名稱:daliylife,代碼行數:15,代碼來源:AMapUtils.java

示例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();
    }
 
開發者ID:kaiwk,項目名稱:Today,代碼行數:14,代碼來源:AMapProvider.java

示例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) + "米");


                }
            }
        }
    });
}
 
開發者ID:CKTim,項目名稱:MyApplication,代碼行數:30,代碼來源:Shopdetail_fragment.java

示例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);

    }
 
開發者ID:joy-inc,項目名稱:joy-app,代碼行數:12,代碼來源:LocationUtil.java

示例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);

    }
 
開發者ID:joy-inc,項目名稱:joy-app,代碼行數:12,代碼來源:LocationUtil.java

示例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();
    }
 
開發者ID:joy-inc,項目名稱:joy-app,代碼行數:10,代碼來源:LocationUtil.java

示例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);
    }
}
 
開發者ID:joy-inc,項目名稱:joy-app,代碼行數:8,代碼來源:LocationUtil.java

示例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);
				}
			}
		}
	});
}
 
開發者ID:amapapi,項目名稱:Android_Location_Demo,代碼行數:66,代碼來源:GeoFence_Old_Activity.java

示例15: stopLocation

import com.amap.api.location.AMapLocationListener; //導入依賴的package包/類
public void stopLocation(AMapLocationListener locationListener){
    mAMapLocationClient.stopLocation();
    mAMapLocationClient.unRegisterLocationListener(locationListener);
    mClientOption = null;
}
 
開發者ID:kaiwk,項目名稱:Today,代碼行數:6,代碼來源:AMapProvider.java


注:本文中的com.amap.api.location.AMapLocationListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。