本文大綱html
地圖服務(Map Kit)給您提供一套地圖開發調用的SDK,地圖數據覆蓋超過200個國家和地區,支持數百種語言,方便您輕鬆地在應用中集成地圖相關的功能,全方位提高用戶體驗。java
關鍵字搜索:經過指定的關鍵字和可選的地理範圍,查詢諸如旅遊景點、企業和學校之類的地點。android
路徑規劃: 是一套以HTTPS形式提供的步行、騎行、駕車路徑規劃以及行駛距離計算接口,經過JSON格式返回路徑查詢數據,提供路徑規劃能力。git
1) 註冊成爲開發者github
註冊地址:
https://developer.huawei.com/consumer/cn/service/josp/agc/index.html?ha_source=hms1json
1) 建立應用,添加sha256,開啓map/site開關,下載json文件app
1) 將「agconnect-services.json」文件拷貝到應用級根目錄下maven
buildscript { repositories { maven { url 'https://developer.huawei.com/repo/' } google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.2' classpath 'com.huawei.agconnect:agcp:1.3.1.300' } } allprojects { repositories { maven { url 'https://developer.huawei.com/repo/' } google() jcenter() } }
2) 在「dependencies 」中添加以下編譯依賴ide
dependencies { implementation 'com.huawei.hms:maps:{version}' implementation 'com.huawei.hms:site:{version}' }
3) 在文件頭添加配置gradle
apply plugin: 'com.huawei.agconnect'
4) 在android中配置簽名。將生成簽名證書指紋生成的簽名文件複製到您工程的app目錄下,並在「build.gradle」文件中配置簽名。
signingConfigs { release { // 簽名證書 storeFile file("**.**") // 密鑰庫口令 storePassword "******" // 別名 keyAlias "******" // 密鑰口令 keyPassword "******" v2SigningEnabled true v2SigningEnabled true } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' debuggable true } debug { debuggable true } }
SearchResultListener<TextSearchResponse> resultListener = new SearchResultListener<TextSearchResponse>() { // Return search results upon a successful search. @Override public void onSearchResult(TextSearchResponse results) { List<Site> siteList; if (results == null || results.getTotalCount() <= 0 || (siteList = results.getSites()) == null || siteList.size() <= 0) { resultTextView.setText("Result is Empty!"); return; } mFirstAdapter.refresh(siteList); StringBuilder response = new StringBuilder("\n"); response.append("success\n"); int count = 1; AddressDetail addressDetail; Coordinate location; Poi poi; CoordinateBounds viewport; for (Site site : siteList) { addressDetail = site.getAddress(); location = site.getLocation(); poi = site.getPoi(); viewport = site.getViewport(); response.append(String.format( "[%s] siteId: '%s', name: %s, formatAddress: %s, country: %s, countryCode: %s, location: %s, poiTypes: %s, viewport is %s \n\n", "" + (count++), site.getSiteId(), site.getName(), site.getFormatAddress(), (addressDetail == null ? "" : addressDetail.getCountry()), (addressDetail == null ? "" : addressDetail.getCountryCode()), (location == null ? "" : (location.getLat() + "," + location.getLng())), (poi == null ? "" : Arrays.toString(poi.getPoiTypes())), (viewport == null ? "" : viewport.getNortheast() + "," + viewport.getSouthwest()))); } resultTextView.setText(response.toString()); Log.d(TAG, "onTextSearchResult: " + response.toString()); } // Return the result code and description upon a search exception. @Override public void onSearchError(SearchStatus status) { resultTextView.setText("Error : " + status.getErrorCode() + " " + status.getErrorMessage()); } }; // Call the place search API. searchService.textSearch(request, resultListener);
NetworkRequestManager.getWalkingRoutePlanningResult(latLng1, latLng2, new NetworkRequestManager.OnNetworkListener() { @Override public void requestSuccess(String result) { generateRoute(result); } @Override public void requestFail(String errorMsg) { Message msg = Message.obtain(); Bundle bundle = new Bundle(); bundle.putString("errorMsg", errorMsg); msg.what = 1; msg.setData(bundle); mHandler.sendMessage(msg); } });
4、項目成果展現
欲瞭解更多詳情,請參閱:
華爲開發者聯盟官網:https://developer.huawei.com/consumer/cn/hms?ha_source=hms1
獲取開發指導文檔:https://developer.huawei.com/consumer/cn/doc/development?ha_source=hms1
參與開發者討論請到Reddit社區:https://www.reddit.com/r/HuaweiDevelopers/
下載demo和示例代碼請到Github:https://github.com/HMS-Core
解決集成問題請到Stack Overflow:https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest
原文連接:https://developer.huawei.com/consumer/cn/forum/topic/0202436666167160224?fid=18
原做者:胡椒