English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Maps Service UI BizBundle

Last Updated on : 2022-09-02 07:52:53download

Maps Service UI BizBundle supports AutoNavi and Google Maps, including the following features:

  • AutoNavi provides multiple services such as positioning and location searching and selection in mainland China.
  • Google Maps helps you implement positioning and geofencing, and apply for permissions.

Integrate with the UI BizBundle

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-22'
    	implementation 'com.tuya.smart:tuyasmart-bizbundle-location_amap:4.2.0-22'
    }
    
  • Support Google Maps only:

    dependencies {
    	implementation 'com.tuya.smart:tuyasmart-bizbundle-map_google:4.2.0-22'
    	implementation 'com.tuya.smart:tuyasmart-bizbundle-location_google:4.2.0-22'
    }
    

Grant service permissions

Request a key

For more information, see Request AutoNavi Key and Apply for Google Map Android API Key.

Configure the 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>

Implement features

AutoNavi

  • 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;
    	}
    }
    

Google Maps

  • 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;
    	}
    }
    

Query location information

  • 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) {
    		//...
    	}
    }
    
    • Before users can get the location information, you must enable the location feature. Otherwise, an empty value will be returned.
    • To fix the problems caused by location permissions, you must request the permissions by yourself. The UI BizBundle provides the permissions settings for the geofencing feature of Google Maps.
    • Users’ mobile phones must support the Google Play service before the Google Maps service can be usedplemented.