Last Updated on : 2023-08-18 06:46:02download
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:4.2.0-33'
implementation 'com.tuya.smart:tuyasmart-bizbundle-location_amap:4.2.0-33'
}
Support Google Maps only:
dependencies {
implementation 'com.tuya.smart:tuyasmart-bizbundle-map_google:4.2.0-32'
implementation 'com.tuya.smart:tuyasmart-bizbundle-location_google:4.2.0-32'
}
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