When users search for a place in the app, they are not satisfied with a single location information, and hope to get more in-depth information that can help them make decisions. For example, users who need taxi travel can display surrounding locations when searching for locations in the taxi app, accurate to a certain intersection, allowing users to freely choose the appropriate pick-up and drop-off point. Banking and financial apps allow users to display nearby offline outlets and business hours, phone numbers, and surrounding road information when searching.
However, developing the relevant information function of search locations in the App requires a large amount of location data and other information. In the face of insufficient data, how can we develop and provide users with access to different types of locations (such as hotels, restaurants, scenic spots) when they view them? What about the ability to target in-depth information such as hours of operation, ratings, etc.?
HMS Core location service provides one-stop search service, has 260+ million global POI data, covers 200+ countries and regions, and supports 70+ languages around the world. The location details function can obtain location details based on the unique primary key location ID of the location, and the location detail information request returns more comprehensive information about the specified location, such as location name, address details, latitude and longitude, etc. For example, when users open logistics apps, they can search for nearby outlets, business hours, phone numbers, etc.; travel apps can search for specific locations of scenic spots, nearby hotels, weather, etc.; LBS games can also be adapted based on location details. When searching for a place, you can view the tasks, players, and regional rankings of that place.
Demo
Development steps
1. Development preparation
1.1 Configuring AppGallery Connect
Before developing an application, you need to configure relevant information in AppGallery Connect.
1.2 Integrate HMS Core SDK
For the Android Studio development environment, Huawei provides the HMS Core SDK package that integrates the Maven warehouse. Before starting development, you need to integrate the HMS Core SDK into your Android Studio development environment.
1.3 Configure the obfuscated script
Before compiling the APK, you need to configure the obfuscation configuration file to avoid obfuscation of the HMS Core SDK resulting in abnormal functions.
For detailed preparation steps, please refer to the official website of Huawei Developer Alliance .
2. Location Details
// 声明SearchService对象
private SearchService searchService;
// 创建SearchService实例
searchService = SearchServiceFactory.create(this, "
API key
");
// 创建请求体
DetailSearchRequest request = new DetailSearchRequest();
request.setSiteId("
C2B922CC4651907A1C463127836D3957
");
request.setLanguage("
fr
");
request.setChildren(
false
);
// 创建搜索结果侦听器
SearchResultListener<DetailSearchResponse> resultListener = new SearchResultListener<DetailSearchResponse>() {
// 正常结果返回
@Override
public void onSearchResult(DetailSearchResponse result) {
Site site;
if (result == null || (site = result.getSite()) == null) {
return;
}
Log.i("TAG", String.format("siteId: '%s', name: %s\r\n", site.getSiteId(), site.getName()));
}
// 异常结果返回
@Override
public void onSearchError(SearchStatus status) {
Log.i("TAG", "Error : " + status.getErrorCode() + " " + status.getErrorMessage());
}
};
// 调用地点详情接口
searchService.detailSearch(request, resultListener);
Learn more details>>
Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee
Follow us to know the latest technical information of HMS Core for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。