当前位置: 首页>>代码示例>>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;未经允许,请勿转载。