地图服务 UI 业务包

更新时间:2024-01-11 01:43:20下载pdf

涂鸦地图服务 UI 业务包主要包含高德地图和 Google 地图的相关功能。包括:

  • 高德地图:中国大陆地区的定位功能、位置搜索选择功能。
  • Google 地图:定位功能、地理围栏功能、权限申请。

集成业务包

在工程 Module 的 build.gradle 添加配置:

  • 只包括高德地图的配置:

    dependencies {
                 api enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:5.8.0")
    	implementation 'com.thingclips.smart:thingsmart-bizbundle-map_amap'
    	implementation 'com.thingclips.smart:thingsmart-bizbundle-location_amap'
    }
    
  • 只包含 Google 地图配置:

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

服务授权

申请 Key

步骤详情,请参考 申请高德地图 key申请 Google 地图安卓 API 密钥

配置 Key

res 资源文件中添加您申请到的地图服务 Key:

<string name="amapKey">高德地图 Key</string>
<string name="google_maps_key">Google 地图 Key</string>

修改 AndroidManifest

AndroidManifest 文件中,application 标签下新增 android:allowNativeHeapPointerTagging="false"

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

功能使用

高德地图

  • 进入高德地图:

    public static final int MAP_RESULT_OK = 10001;
    UrlRouter.execute(UrlRouter.makeBuilder(LocationActivity.this, "map_location_setting", bundle, 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 地图:

    //进入 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) {
    		//……
    	}
    }
    
    • 获取定位前,您需要提前启动定位。否则,直接获取的是空值。
    • 如果遇到定位权限问题,您需要自行添加权限申请。其中,UI 业务包已添加了 Google 地理围栏权限配置。
    • 用户的设备必须支持 Google Play 服务,才可以运行 Google 地图相关功能。