更新时间:2023-05-22 06:38:29下载pdf
涂鸦地图服务 UI 业务包主要包含高德地图和 Google 地图的相关功能。包括:
在工程 Module 的 build.gradle
添加配置:
只包括高德地图的配置:
dependencies {
implementation 'com.tuya.smart:tuyasmart-bizbundle-map_amap:1.0.0-cube'
implementation 'com.tuya.smart:tuyasmart-bizbundle-location_amap:1.0.0-cube'
}
只包含 Google 地图配置:
dependencies {
implementation 'com.tuya.smart:tuyasmart-bizbundle-map_google:1.0.0-cube'
implementation 'com.tuya.smart:tuyasmart-bizbundle-location_google:1.0.0-cube'
}
步骤详情,请参考 申请高德地图 key 和 申请 Google 地图安卓 API 密钥。
在 res
资源文件中添加您申请到的地图服务 Key:
<string name="amapKey">高德地图 Key</string>
<string name="google_maps_key">Google 地图 Key</string>
进入高德地图:
public static final int MAP_RESULT_OK = 10001;
UrlRouter.execute(UrlRouter.makeBuilder(mContext, "map_location_setting", null, MAP_RESULT_OK));
接收返回数据:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (resultCode) {
case MAP_RESULT_OK: {
if (null != data) {
double lat = data.getDoubleExtra("lat", 0);
double lng = data.getDoubleExtra("lng", 0);
String mCountry = data.getStringExtra("country");
String mProvince = data.getStringExtra("province");
String mCity = data.getStringExtra("city");
String mAddress = data.getStringExtra("address");
}
}
break;
default:
break;
}
}
进入 Google 地图:
//进入 Google 地理围栏
UrlRouter.execute(UrlRouter.makeBuilder(mContext, "map_geofence", bundle, GEOSELECT_REQUEST_CORE));
接收返回数据:
//接收返回数据
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (resultCode) {
case GEOSELECT_REQUEST_CORE: {
if(null != data) {
double lat = data.getDoubleExtra("lat", 0);
double lng = data.getDoubleExtra("lng", 0);
int mRadius = data.getIntExtra("radius", 0);
String mAddress = TextUtils.isEmpty(data.getStringExtra("address")) ? "" : data.getStringExtra("address");
}
}
break;
default:
break;
}
}
唤起定位:
LocationService locationService = MicroServiceManager.getInstance().findServiceByInterface(LocationService.class.getName());
if (locationService!=null) {
locationService.updateLocation();
}
获取定位信息:
LocationService locationService = MicroServiceManager.getInstance().findServiceByInterface(LocationService.class.getName());
if (locationService!=null) {
LocationBean location = locationService.getLocation();
if (location != null) {
//……
}
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈