Huawei Ability Gallery — Showing Nearby Places on the Card (Part 2)

Yağmur Kılıç
Huawei Developers
Published in
4 min readJan 14, 2022

Users can see nearby places on Huawei Assistant Page through Huawei Ability Gallery.

In This article, we are going to learn how we can do that step by step. “Huawei Ability Gallery — Showing Nearby Places on the Card” consists of two parts.

The first part is the development and design of a card to show the user nearby places. You can take a look at the article below for the first part.

We are going to focus on the second step in this article. You can take a look at the links below for other steps.

The second part includes the following steps.

  1. Obtain the user device location by using Huawei Location Kit- Fused Location (API).
  2. Search for nearby places based on the user device location using Huawei Site Kit — Nearby Place Search service
  3. Develop a service to send nearby places to “Huawei Ability Gallery”.

Obtaining the User Device Location

As a beginning step in we need to get the current user location. In this app, Huawei Fused Location API is used to get the current location then this location sends to the server. For details, please review Fused Location Service.

Searching for Nearby Places Based on User Device Location

Secondly, we search nearby banks using user location. For details about nearby search API, please refer to Nearby Place Search.

Search Nearby Places API

  • Protocol: HTTPS POST
  • Direction: Your server -> Map Kit server
  • URL:https://siteapi.cloud.huawei.com/mapApi/v1/siteService/nearbySearch?key=API KEY
  • NOTE
    * For details about API KEY, please refer to Obtaining the API Key.
    * You need to call the URLEncoder.encode(“Your apiKey”, “UTF-8”) method to encode the API key using encodeURI. For example, if the original API key is ABC/DFG+, the conversion result is ABC%2FDFG%2B.
  • Data Format
    Request: Content-Type: application/JSON
    Response: Content-Type: application/JSON

Constant Values ​​in Code

  • POI_TYPE: BANK
  • radius: 2000
  • pageSize: 3

Create an entity request to search nearby banks.

Create an HTTP Post for sending requests to the Huawei Map Kit server.

Call for Nearby Search API on line 10 and check response status.

Developing Event Push Service

The last step is developing an event push API. Nearby banks are sent to Huawei Ability Gallery (HAG) for displaying on the card via this API.

HUAWEI Ability Gallery checks the validity of each card triggered during event pushing. It will not store invalid cards and will delete expired cards.

If this is your first time learning about Event Push, please start by reading the following article.

Event Card Validity Checking Rules
Formal state

  • Event card effective time = Effective time in the event push request.
  • Event card expiration time = MIN (Effective time in the event push request + Event stay duration configured in HUAWEI Ability Gallery, Expiration time in the event push request)

Test state

  • Event card effective time = MAX (Server time when the event is received, Effective time in the event push request)
  • Event card expiration time = MIN (Server time when the event is received + Default stay duration (72 hours), Effective time in the event push request + Event stay duration (configured in HUAWEI Ability Gallery, 999 hours at most))

Note

  • If the effective time in the event push request is later than the expiration time, the event is invalid.
  • If the expiration time in the event push request is earlier than the current server time, the event is invalid.
  • If the event card expiration time is earlier than the current server time, the card is invalid.

Event Push API

For details about sending event push, please refer to Event Push.
Create an HTTP Post for sending requests to the HAG server.

Firstly the developer’s server obtains permission to call the event notification API of HUAWEI Ability Gallery. For details, please refer to Gaining Account Authorization from a Huawei User.

Apply for an app ID on HUAWEI Developer, and obtain an app-level access token (AT).

Send an event message to users informing them about banks nearby. The event message contains the event name user’s OpenID and card parameters.

OpenID assigned by Huawei to associate user’s ID in your app with the user’s HUAWEI ID. This parameter is mandatory for user events

Conclusion

I hope this article helps you better understand the Huawei Ability Gallery cases.

Thanks for reading. If you have a question, don’t hesitate to contact me.

Reference

--

--