1

​1. Guide

On July 31st, Huawei HarmonyOS Developer Day will be held in Hangzhou. Open Platform Map SDK has been the first in the industry to realize the migration and reconstruction of Harmony. 16103a381d13ca fully adapts to HarmonyOS and releases for developers free of charge. Developers can go to the official website of AutoNavi Open Platform to learn more, and get support for version downloads, development documents, FAQs, etc.

Open Platform: 16103a381d13f7 https://lbs.amap.com/

On June 2 this year, Huawei officially released HarmonyOS. Since HarmonyOS has special requirements for compatibility with Android, if the APP application is developed with the Android API, the developer can directly use the Android SDK.

But if the app is developed using the HarmonyOS API, you cannot use the Android SDK and need to use the HarmonyOS version of the SDK.

In order to facilitate developers to develop LBS services in the corresponding devices of HarmonyOS, AutoNavi Open Platform took the lead in adapting HarmonyOS. The first batch of adaptations includes maps and search SDKs, and supports the embedding of mobile phones, Pads and other smart terminals equipped with HarmonyOS. equipment.

2. HarmonyOS map SDK feature introduction

and AutoNavi Open Platform Android Map SDK Smooth Switch

  • Developers who have integrated the Android map SDK of the AutoNavi open platform can seamlessly switch to the HarmonyOS map SDK without additional development. The interface changes between HarmonyOS and the Android system are digested by the AutoNavi Open Platform SDK adaptation layer, and the SDK external interface remains unchanged.
  • AutoNavi’s underlying engine is connected to HarmonyOS NDK, and the upper code is fully connected to HarmonyOS SDK. All system interfaces use HarmonyOS API.

AutoNavi open platform Android/iOS map SDK feature highlights

  • Developers can easily complete the map construction work through the AutoNavi open platform API and SDK, and present the map exquisitely in your application. Map SDK not only provides rich map coverage drawing capabilities, but also supports search, multiple path planning, coordinate conversion, distance measurement, area calculation and other functions.
  • After adapting to HarmonyOS, the map SDK still supports the use of peripheral tools such as the custom map SaaS platform. Developers can customize more than 40 types of areas, buildings, water systems, sky, roads, annotations, and administrative boundaries in the platform. A variety of map elements, flexible design of your favorite map style. For more details on the basic capabilities, customization, and visualization capabilities of the map SDK, please refer to the official website of AutoNavi Open Platform.

HarmonyOS version map SDK overall framework

HarmonyOS and Android systems are very different. Almost all APIs have been adjusted, and many APIs have adjusted their implementation schemes, so they cannot be adapted by changing the package name. We switch all the code that calls Android in the native SDK to the adaptation layer, and adapt the SDK interfaces to the HarmonyOS interface one by one in the adaptation layer.

The overall framework of the HarmonyOS map SDK is roughly as follows:

Third, how to integrate-from scratch

first step to build a HarmonyOS development environment

Complete DevEco Studio installation, environment configuration and project creation, refer to HarmonyOS official website instructions: https://developer.harmonyos.com/cn/docs/documentation/doc-guides/start-overview-000000000002960

second step is to configure the signature information of the application

After the application project is created, you need to configure the signature information before you can use the real machine to debug and publish the application.

third step is to obtain the appId of the application

After configuring the signature information, you can get the appId of the current application. This appId is mainly used to apply for AutoNavi’s apiKey. Please confirm the appId of the final application to prevent the final AutoNavi SDK authentication from failing.

The way to get the appId of the application through code is as follows:

getApplicationContext().getBundleManager().getBundleInfo(getBundleName(), 0).getAppId()

Note : At present, the appId obtained through DevEco Studio connected to the cloud real machine is not complete, only "package name_" is obtained. When using the cloud real machine to debug the AutoNavi Map SDK, the authentication will fail. The correct appId form is: "package name_signature information", for example: com.amap.demo_BGtGgVB3ASqU7XXXXV2/zhoYh6tFQHAd5DASWVTEAgvZfzrEGljjs=

fourth step is to apply for API Key

Create a new application

Create a new application from the entrance-console in the upper right corner of the official website of the open platform. If you have created an application before, you can skip this step.

Add new Key

Click the "Add New Key" button on the created application, and in the pop-up dialog box, in sequence: enter the application name, select the bound service as "Harmony Platform SDK", and enter the AppID, as shown in the following figure:

Note: 1 Key can only be used for one application (multi-channel installation package belongs to multiple applications), and 1 Key used in multiple applications will cause service call failure.

After reading the API Terms of Service of AutoNavi Maps, check this option and click "Submit" to complete the Key application. At this time, you can see the Key you just applied for under the created application.

Step 5 Set the applied Key in the code

Please use API to set the applied API Key of AutoNavi to AutoNavi Map SDK.

/**
 * 动态设置apiKey。
 *
 * @param apiKey 在高德官网上申请的apiKey。
 */
MapsInitializer.setApiKey(String apiKey)

Note: Please make sure to set the API Key to the AutoNavi Map SDK before calling any API of AutoNavi Map SDK. It is recommended to put it in the initialization of Application.

After completing the above 5 steps, you can use the HarmonyOS version of the Gaode Map SDK happily.

IV. How to use-create a map

Before using the map SDK, you need to set relevant permissions in the config.json file to ensure that the map function can be used normally.

first step is to configure config.json

First, declare permissions.

...
"reqPermissions": [
      {
        "usedScene": {
          "ability": [
            "com.example.harmonysearchsdk.MainAbility"
          ],
          "when": "always"
        },
        "reason": "request internet",
        "name": "ohos.permission.INTERNET"
      }
    ]
...

second step is to add map development kit

Put the har package into the libs directory and add dependencies in turn.

dependencies {
    implementation files("libs/xxx.har")
    //...
}

Or directly use the method of importing all har packages under libs:

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
    //...
}

third step is to initialize the map container

Set Key

Please refer to the fourth step of the "Starting from Zero" chapter above to obtain the Key.

MapsInitializer.setApiKey("您的key");

Create MapView

public class BasicMapDemoSlice extends Ability {

    private MapView mapView;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        initMapView();
    }

    private void initMapView() {
        mapView = new MapView(this);

        mapView.onCreate(null);
        mapView.onResume();
        DirectionalLayout.LayoutConfig config = new DirectionalLayout.LayoutConfig(
                DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_PARENT);
        mapView.setLayoutConfig(config);
        super.setUIContent(mapView);
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mapView != null) {
            mapView.onDestroy();
        }
    }
}

Initialize the map and get the AMap object

AMap aMap = mapView.getMap();
aMap.setOnMapLoadedListener(new AMap.OnMapLoadedListener() {
    @Override
    public void onMapLoaded() {
    // todo
    }
});

At this point, you can see the map display, and after getting the AMap object, you can add overlays such as dots, lines, and polygons to the map.

5. Get more details and development support

Open Platform: 16103a381d1bdc https://lbs.amap.com/

Get HarmonyOS version of AutoNavi Map SDK download, development documents, Demo and other development support: https://lbs.amap.com/api/harmonyos-sdk/summary/


高德技术
458 声望1.8k 粉丝

关于高德的技术创新内容将呈现于此


引用和评论

0 条评论