Maps Service UI BizBundle

Last Updated on : 2024-04-28 06:07:47download

The Maps Service UI BizBundle supports Amap and Google Maps with the following features:

  • Amap: Positioning and location search services for users in mainland China.
  • Google Maps: Positioning, geofencing, and location permission requests.

Integrate with the UI BizBundle

Add the following dependencies to the file build.gradle of module:

  • Support AutoNavi only:

     
     dependencies {
         api enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:${biz_bom_version}")
         implementation 'com.thingclips.smart:thingsmart-bizbundle-map_amap'
         implementation 'com.thingclips.smart:thingsmart-bizbundle-location_amap'
         api "com.thingclips.smart:thingsmart:${sdk_version}}"
     }
     
     
  • Support Google Maps only:

     
     dependencies {
         api enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:${biz_bom_version}")
        implementation 'com.thingclips.smart:thingsmart-bizbundle-map_google'
        implementation 'com.thingclips.smart:thingsmart-bizbundle-location_google'
         api "com.thingclips.smart:thingsmart:${sdk_version}}"
     }
     
     

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>

Modify AndroidManifest

In the AndroidManifest file, add android:allowNativeHeapPointerTagging="false" under the application tag.

    <application
        android:allowNativeHeapPointerTagging="false"
       >
    </application>

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 implemented.