Last Updated on : 2023-05-22 06:38:29download
Maps Service UI BizBundle supports AutoNavi and Google Maps, including the following features:
Add the following dependencies to the file build.gradle
of module:
Support AutoNavi only:
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'
}
Support Google Maps only:
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'
}
For more information, see Request AutoNavi Key and Apply for Google Map Android API Key.
Add the following key information to the resource file res
:
<string name="amapKey">AutoNavi Key</string>
<string name="google_maps_key">Google Maps Key</string>
Accesses the AutoNavi service:
public static final int MAP_RESULT_OK = 10001;
UrlRouter.execute(UrlRouter.makeBuilder(mContext, "map_location_setting", null, MAP_RESULT_OK));
Receives returned data:
@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;
}
}
Accesses the Google Maps service:
// Accesses the geofencing feature of Google Maps.
UrlRouter.execute(UrlRouter.makeBuilder(mContext, "map_geofence", bundle, GEOSELECT_REQUEST_CORE));
Receives returned data:
// Receives returned data.
@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;
}
}
Enables the location feature:
LocationService locationService = MicroServiceManager.getInstance().findServiceByInterface(LocationService.class.getName());
if (locationService!=null) {
locationService.updateLocation();
}
Returns the location information:
LocationService locationService = MicroServiceManager.getInstance().findServiceByInterface(LocationService.class.getName());
if (locationService!=null) {
LocationBean location = locationService.getLocation();
if (location != null) {
//...
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback