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


Java AMapLocation類代碼示例

本文整理匯總了Java中com.amap.api.location.AMapLocation的典型用法代碼示例。如果您正苦於以下問題:Java AMapLocation類的具體用法?Java AMapLocation怎麽用?Java AMapLocation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AMapLocation類屬於com.amap.api.location包,在下文中一共展示了AMapLocation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initLocation

import com.amap.api.location.AMapLocation; //導入依賴的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: onLocationChanged

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (mListener != null && aMapLocation != null) {
        if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {
            mAMapLocation = aMapLocation;
            mlocationClient.stopLocation();
            mListener.onLocationChanged(aMapLocation);// 顯示係統小藍點
            lp = new LatLonPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
            mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lp.getLatitude(), lp.getLongitude()), 17));
            doSearchQuery(aMapLocation.getPoiName().trim(), aMapLocation.getCityCode(), false);
        } else {
            String errText = "定位失敗," + aMapLocation.getErrorCode() + ": " + aMapLocation.getErrorInfo();
            ToastUtils.showToast(this, errText);
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:PoiAroundSearchActivity.java

示例3: onLocationChanged

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (aMapLocation != null) {
        if (aMapLocation.getErrorCode() == 0) {
            String lat = aMapLocation.getLatitude() + "";
            String lng = aMapLocation.getLongitude() + "";

            sharedPref.edit().putString("Latitude", lat).apply();
            sharedPref.edit().putString("Longitude", lng).apply();

        } else {
            Toast.makeText(
                    MainActivity.this,
                    aMapLocation.getErrorInfo(),
                    Toast.LENGTH_LONG
            ).show();
        }
    }
}
 
開發者ID:SEALiu,項目名稱:Calendouer,代碼行數:20,代碼來源:MainActivity.java

示例4: setCity

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
/**
 * 設置當前城市
 * @param amapLocation
 */
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void setCity(AMapLocation amapLocation) {
    if(amapLocation!=null){
        this.city = amapLocation.getCity();
    }
}
 
開發者ID:Vicent9920,項目名稱:MyMap,代碼行數:11,代碼來源:PoiSearchActivity.java

示例5: onLocationChanged

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
/**
     * 實現定位
     * @param amapLocation
     */
    @Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (mListener != null && amapLocation != null) {
            if (amapLocation != null
                    &&amapLocation.getErrorCode() == 0) {

                if(isFirstTime){//隻要第一次的數據,當然,也可以在這裏關閉定位
//                    mlocationClient.stopLocation();//停止定位
                    mListener.onLocationChanged(amapLocation);// 顯示係統小藍點
                    lvHolder.title = "[位置]";
                    lvHolder.address = amapLocation.getProvider()+amapLocation.getCity()+amapLocation.getStreet()+amapLocation.getStreetNum();
                    lvHolder.lp = new LatLonPoint(amapLocation.getLatitude(),amapLocation.getLongitude());
                    mEndMarker.setPosition(new LatLng(amapLocation.getLatitude(),amapLocation.getLongitude()));
                    data.add(0,lvHolder);
                    doSearchQuery();

                }

            } else {
                String errText = "定位失敗," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo();
                Log.e("AmapErr",errText);
            }
        }
    }
 
開發者ID:Vicent9920,項目名稱:MyMap,代碼行數:29,代碼來源:PiclocationActivity.java

示例6: onLocationChanged

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
/**
 * 定位地點
 * @param amapLocation
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
    if (mListener != null&&amapLocation != null) {
        EventBus.getDefault().post(amapLocation);
        if (amapLocation != null
                &&amapLocation.getErrorCode() == 0) {
            if(startList.size()==0)
                startList.add(new NaviLatLng(amapLocation.getLatitude(),amapLocation.getLongitude()));
            if(!calculateSuccess){
                mListener.onLocationChanged(amapLocation);// 顯示係統小藍點
            }

        } else {
            String errText = "定位失敗," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo();
            Log.e("AmapErr",errText);
        }
    }
}
 
開發者ID:Vicent9920,項目名稱:MyMap,代碼行數:23,代碼來源:NavigationActivity.java

示例7: notifyLocationChanged

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
@Override
public void notifyLocationChanged(LocationSource.OnLocationChangedListener amListener, AMapLocation aMapLocation) {
    if(mGpsPowerListener != null){
        mGpsPowerListener.onGpsPower(aMapLocation.getGpsAccuracyStatus());
    }
    for(ILocationFilter locationFilter : mLocationFilterList) {
        if(!locationFilter.accept(mPrevoiusLocation, aMapLocation)){
            return;
        }
    }
    mPrevoiusLocation = aMapLocation;
    amListener.onLocationChanged(aMapLocation);
    if(mOnNewLocationListener != null){
        mOnNewLocationListener.onNewLocation(aMapLocation);
    }
}
 
開發者ID:stdnull,項目名稱:RunMap,代碼行數:17,代碼來源:AmapWrapper.java

示例8: accept

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
@Override
public boolean accept(AMapLocation previous, AMapLocation current) {
    if(previous == null){
        return true;
    }
    LatLng pre = new LatLng(previous.getLatitude(), previous.getLongitude());
    LatLng cur = new LatLng(current.getLatitude(), current.getLongitude());
    float distance = AMapUtils.calculateLineDistance(pre, cur);
    if(distance < RMConfiguration.DRAW_DISTANCE){
        return false;
    }
    float speed = current.getSpeed();
    double interval = (SystemClock.elapsedRealtime() - mPreviousUpdateTime)/1000.0;
    float v = (float) (distance/interval);
    if(v > RMConfiguration.MAX_SPEED || v > speed * 1.5){
        return false;
    }
    mPreviousUpdateTime = SystemClock.elapsedRealtime();
    return true;
}
 
開發者ID:stdnull,項目名稱:RunMap,代碼行數:21,代碼來源:SpeedAndDistanceFilter.java

示例9: fun_getGeolocation

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
@JavascriptInterface
public void fun_getGeolocation(String jsonString) {
    JSInBean jsInBean = JSBridgeUtil.getInstance().parseJsonArray(jsonString);
    StringBuilder builder = new StringBuilder();
    AMapLocation location = AMapLocationTool.getInstance().location();
    builder.append("{");
    builder.append("\"permission\":" + (this.mActivity.getPackageManager().checkPermission("android.permission.ACCESS_COARSE_LOCATION", BaseApplication.getInstance().getPackageName()) == 0 ? "1" : "0") + ",");
    builder.append("\"longitude\":" + location.getLongitude() + ",");
    builder.append("\"latitude\":" + location.getLatitude() + ",");
    builder.append("\"horizontalAccuracy\":0,");
    builder.append("\"verticalAccuracy\":0,");
    builder.append("\"altitude\":" + location.getAltitude() + ",");
    builder.append("\"altitudeAccuracy\":0");
    builder.append("}");
    jsCallBack(jsInBean, builder.toString());
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:JavaScriptinterface.java

示例10: location

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
public synchronized AMapLocation location() {
    if (!this.isStart) {
        if (this.mLocationClient != null) {
            this.mLocationClient.setLocationListener(this.myListener);
            setLocationOption();
            this.mLocationClient.startLocation();
            this.isStart = true;
        } else {
            this.mLocationClient = new AMapLocationClient(BaseApplication.getInstance().getBaseContext());
            this.mLocationClient.setLocationListener(this.myListener);
            setLocationOption();
            this.mLocationClient.startLocation();
            this.isStart = true;
        }
    }
    this.mHandler.postDelayed(new 1(this), 5000);
    if (this.mLocationClient != null) {
        AMapLocation location = this.mLocationClient.getLastKnownLocation();
        if (location != null) {
            this.lastBdLocation = location;
        }
    }
    return this.lastBdLocation;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:AMapLocationTool.java

示例11: statisticsLoginAndEnv

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
public static void statisticsLoginAndEnv(Context context, int st, boolean isLogin) {
    String loginProperty = "plat=" + LetvConfig.getSource();
    AMapLocation location = AMapLocationTool.getInstance().location();
    String lo = "";
    String la = "";
    if (location != null) {
        lo = String.valueOf(location.getLongitude());
        la = String.valueOf(location.getLatitude());
    }
    if (TextUtils.isEmpty(lo) && TextUtils.isEmpty(la)) {
        lo = PreferencesManager.getInstance().getLocationLongitude() + "";
        la = PreferencesManager.getInstance().getLocationLatitude() + "";
    }
    int i = st;
    DataStatistics.getInstance().sendLoginAndEnvInfo(context.getApplicationContext(), LetvUtils.getUID(), loginProperty, sLoginRef, String.valueOf(System.currentTimeMillis() / 1000), LetvUtils.getPcode(), i, null, LetvConfig.getSource(), lo, la, PreferencesManager.getInstance().getStatisticsLocation(), isLogin);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:StatisticsUtils.java

示例12: initLocation

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
/**
 * 初始化百度地圖
 */
private void initLocation() {
    AMapLocation location = locationClient.getLastKnownLocation();
    if (location != null) {
        Log.d(TAG, "getLastKnownLocation success");
        mLongitude = location.getLongitude();
        mLatitude = location.getLatitude();
        city = location.getCity();
        country = location.getCountry();
        Log.d("XLight", String.format("long:%s,latitude:%s,ciry:%s,country:%s", mLongitude, mLatitude, city, country));
        //請求天氣信息
        updateLocationInfo();
    } else {
        // 啟動定位
        locationClient.startLocation();
    }
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:20,代碼來源:GlanceMainFragment.java

示例13: onLocationChanged

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
@Override
public void onLocationChanged(AMapLocation loc) {
    if (null != loc && loc.getErrorCode() == 0) {
        //解析定位結果
        mLongitude = loc.getLongitude();
        mLatitude = loc.getLatitude();
        city = loc.getCity();
        country = loc.getCountry();
        Log.i("XLight", String.format("long:%s,latitude:%s,city:%s,country:%s", mLongitude, mLatitude, city, country));
        //請求天氣信息
        updateLocationInfo();
        locationClient.stopLocation();
    } else {
        // 定位失敗,顯示提示
        Log.e("XLight", "location Error, ErrCode:"
                + loc.getErrorCode() + ", errInfo:"
                + loc.getErrorInfo());
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ToastUtil.showToast(getActivity(), R.string.open_gps);
            }
        });
    }
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:26,代碼來源:GlanceMainFragment.java

示例14: onLocationChanged

import com.amap.api.location.AMapLocation; //導入依賴的package包/類
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (aMapLocation != null) {
        if (aMapLocation.getErrorCode() == 0) {
            mCity = aMapLocation.getCity();
            mSwipeRefreshLayout.setEnabled(true);
            mSwipeRefreshLayout.post(new Runnable() {
                @Override
                public void run() {
                    mSwipeRefreshLayout.setRefreshing(true);
                }
            });
            getWeatherData(mCity);
        }
        //定位失敗,通過ErrCode(錯誤碼)信息來確定失敗的原因,errInfo是錯誤信息
        else {
            SnackBarUtil.showSnackBar(aMapLocation.getErrorInfo(), mSwipeRefreshLayout, getActivity());
        }
    }
}
 
開發者ID:xiarunhao123,項目名稱:PureNews,代碼行數:21,代碼來源:WeatherFragment.java

示例15: initLocation

import com.amap.api.location.AMapLocation; //導入依賴的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


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