Longitude and latitude are precise coordinates to determine the location of each location. Using coordinates to describe a location is very accurate but not intuitive, and it is not user-friendly to express. HMS Core location service provides a reverse geocoding function, which can obtain detailed addresses of nearby places through latitude, and convert coordinates into geographic descriptions. For example, a point can be marked on the map of an e-commerce app to display the specific location; drag the map in a taxi or takeaway app or click a point on the map, the positioning marker can select a suitable nearby pickup address or takeaway address; In the logistics distribution app, it is necessary to accurately and intuitively describe the route where the logistics vehicle is located and the logistics distribution point, and use the reverse geocoding function to confirm the location of the vehicle through the returned latitude and longitude coordinates.
The inverse geocoding function of HMS Core location service has a strong address understanding ability, using a more localized location expression, the accuracy rate is as high as 90%, it supports 79 languages, and the delay is as low as 200ms.
Demo
Development steps
Preparation for integration
Register as a developer
Before developing an app, you need to register as a developer on the HUAWEI Developer Alliance website and complete real-name authentication. For details, see Account Registration Authentication.
Create an app
See Creating a Project and Creating an Application to complete the application creation.
Generate and configure the signing certificate thumbprint
The signature certificate fingerprint is used to verify the authenticity of the application. You need to generate the signature certificate fingerprint locally based on the signature certificate, and configure the signature certificate fingerprint in AppGallery Connect before the application is launched.
See the official website for specific steps.
Integrated SDK
For the Android Studio development environment, Huawei provides an SDK package that integrates the Maven warehouse. Before starting development, you need to integrate the SDK into your Android Studio development environment.
See the official website for specific steps.
Development steps
1. Create a geocoding service client
Create a GeocoderService instance in the onClick() method in GeocoderActivity that uses the geocoding service in your project, and call the geocoding related interfaces through this instance.
Locale locale = new Locale("zh", "CN");
GeocoderService geocoderService = LocationServices.getGeocoderService(GeocoderActivity.this, locale);
2. Get Reverse Geocoding Information
If you want the application to obtain reverse geocoding information, you can use the getFromLocation() interface provided by the GeocoderService object in the location service. This interface will return a List< HWLocation > object containing location information according to the GetFromLocationRequest request information you set.
2.1. Set the reverse geocoding request parameters.
// 参数一:纬度
// 参数二:经度
// 参数三:返回结果最大数量
// 请传入合理的地区经纬度,否则没有相关地理信息返回。如果是非中国地区,请传入非中国地区的经纬度,且确保经纬度是准确的。
GetFromLocationRequest getFromLocationRequest = new GetFromLocationRequest(39.985071, 116.501717, 5);
2.2. Call the getFromLocation() interface to obtain reverse geocoding information.
private void getReverseGeocoding() {
//初始化GeocoderService对象
if (geocoderService == null) {
geocoderService = new GeocoderService(this, new Locale("zh", "CN"));
}
geocoderService.getFromLocation(getFromLocationRequest)
.addOnSuccessListener(new OnSuccessListener<List<HWLocation>>() {
@Override
public void onSuccess(List<HWLocation> hwLocation) {
// TODO:接口调用成功的处理
if (null != hwLocation && hwLocation.size() > 0) {
Log.d(TAG, "hwLocation数据集数量: " + hwLocation.size());
Log.d(TAG, "CountryName: " + hwLocation.get(0).getCountryName());
Log.d(TAG, "City: " + hwLocation.get(0).getCity());
Log.d(TAG, "Street: " + hwLocation.get(0).getStreet());
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// TODO:接口调用失败的处理
}
});
}
2.3. The Log log is:
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) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。