1.权限注册;
2.key配置;
3.注册
mLocationManager = TencentLocationManager.getInstance(this);
4.隐私注册(我就是这一个没有注册)
TencentLocationManager.setUserAgreePrivacy(true);
5.定位权限设置及访问
TencentLocationRequest request = TencentLocationRequest.create(); request.setInterval(10000) .setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_ADMIN_AREA) .setAllowGPS(true) .setAllowDirection(true) .setIndoorLocationMode(true) .setLocMode(TencentLocationRequest.HIGH_ACCURACY_MODE) .setGpsFirstTimeOut(5*1000) .setGpsFirst(true); mLocationManager.requestLocationUpdates(request, this);
6.添加权限是否通过
// 检查定位权限 if (!hasPermissions(this, REQUIRED_PERMISSIONS)) { ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE_LOCATION); } else { // 权限已经被授予, 可以开始使用腾讯地图SDK进行定位 }
7.新建监听
项目 implements TencentLocationListener
@Override public void onLocationChanged(TencentLocation tencentLocation, int i, String s) { // 在这里处理定位结果 if (tencentLocation != null) { double latitude = tencentLocation.getLatitude(); double longitude = tencentLocation.getLongitude(); // 使用经纬度信息 textView.setText(String.valueOf(latitude+longitude)); Log.d("MyActivity", "Location updates " +latitude+longitude); } } @Override public void onStatusUpdate(String s, int i, String s1) { // 定位状态改变时的回调 Log.d("MyActivity", "onStatusUpdate"); }