Android 使用高德地图定位(Google play)国外定位

申请key这些我就不说了,不懂的同学可以去高德地图开放平台查看详细介绍

1.下载依赖 

https://lbs.amap.com/api/android-location-sdk/download

Android 使用高德地图定位(Google play)国外定位_第1张图片

因为是要国外定外 所以下载这个GooglePlay渠道包  然后解压  获取里面的jar包(其他定位配置参考高德地图定位文档)

解压后将AMap_Location的jar包放到工程的libs目录下

定位代码:

    //声明AMapLocationClient类对象
    public AMapLocationClient aMapLocationClient = null;
    private void initLocation() {
        aMapLocationClient = new AMapLocationClient(this);
        AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //设置是否返回地址信息(默认返回地址信息)
        mLocationOption.setNeedAddress(true);
        //关闭缓存机制
        mLocationOption.setLocationCacheEnable(false);
        //给定位客户端对象设置定位参数
        aMapLocationClient.setLocationOption(mLocationOption);
        aMapLocationClient.setLocationListener(mAMapLocationListener);
        //启动定位
        aMapLocationClient.startLocation();
    }

    AMapLocationListener mAMapLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation amapLocation) {
            if (amapLocation != null) {
                if (amapLocation.getErrorCode() == 0) {
                    //可在其中解析amapLocation获取相应内容。
                    Log.e("mAMapLocationListener", amapLocation.getLatitude() + "," + amapLocation.getLongitude() + "," + amapLocation.getCountry() + "," + amapLocation.getCity() + "," + amapLocation.getAddress());
                } else {
                    //定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
                    Log.e("AmapError", "location Error, ErrCode:"
                            + amapLocation.getErrorCode() + ", errInfo:"
                            + amapLocation.getErrorInfo());
                }
            }
        }
    };

 

你可能感兴趣的:(Android)