成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

鴻蒙開源地圖,OSMDroid地圖項目移植到鴻蒙上

開源
OSMDroid-ohos是Google開源地圖項目OSMDroid移植到HarmonyOS系統上的精簡版,可以實現在HarmonyOS系統上做地圖應用開發。當前OSMDroid-ohos地圖根據國內開發情況,默認移植了高德的瓦片地圖顯示。

[[414372]]

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com

OSMDroid-ohos

介紹

OSMDroid-ohos是Google開源地圖項目OSMDroid移植到HarmonyOS系統上的精簡版,可以實現在HarmonyOS系統上做地圖應用開發。當前OSMDroid-ohos地圖根據國內開發情況,默認移植了高德的瓦片地圖顯示。

OSMDroid-ohos地圖提供基本瓦片地圖顯示,地圖指南針覆蓋物,地圖定位坐標覆蓋物,提供單指手勢拖拽地圖功能,單指手勢雙擊放大地圖功能,雙指手勢縮放地圖功能,雙指手勢旋轉地圖功能。

鴻蒙開源地圖,OSMDroid地圖項目移植到鴻蒙上-鴻蒙HarmonyOS技術社區
鴻蒙開源地圖,OSMDroid地圖項目移植到鴻蒙上-鴻蒙HarmonyOS技術社區

MapView使用

xml布局添加

  1. <DependentLayout 
  2.       ohos:id="$+id:osm_map_container" 
  3.       ohos:height="match_content" 
  4.       ohos:width="match_parent"
  5.  
  6.       <com.talkweb.osmharmony.views.MapView 
  7.           ohos:id="$+id:osm_map_view" 
  8.           ohos:height="match_parent" 
  9.           ohos:width="match_parent" 
  10.           ohos:horizontal_center="true"/> 
  11.        
  12.       ················· 
  1. mMapContainerView = (DependentLayout) findComponentById(ResourceTable.Id_osm_map_container); 
  2. mapView = (MapView) findComponentById(ResourceTable.Id_osm_map_view); 

java代碼添加

  1. mMapContainerView = (DependentLayout) findComponentById(ResourceTable.Id_osm_map_container); 
  2. DependentLayout.LayoutConfig layoutConfig = new DependentLayout.LayoutConfig(); 
  3. layoutConfig.width = DependentLayout.LayoutConfig.MATCH_PARENT; 
  4. layoutConfig.height = DependentLayout.LayoutConfig.MATCH_PARENT; 
  5.  
  6. //實例化MapView 
  7. mapView = new MapView(this); 
  8. mMapContainerView.addComponent(mapView, 0, layoutConfig); 

請求相應權限

config.json配置文件添加權限

  1. ······  
  2.  
  3. "module": { 
  4.     "reqPermissions": [ 
  5.       {"name""ohos.permission.LOCATION"}, 
  6.       {"name""ohos.permission.LOCATION_IN_BACKGROUND"}, 
  7.       {"name""ohos.permission.ACCELEROMETER"}, 
  8.       {"name""ohos.permission.GET_NETWORK_INFO"}, 
  9.       {"name""ohos.permission.SET_NETWORK_INFO"}, 
  10.       {"name""ohos.permission.INTERNET"}, 
  11.       {"name""ohos.permission.GYROSCOPE"}, 
  12.       {"name""ohos.permission.READ_USER_STORAGE"}, 
  13.       {"name""ohos.permission.WRITE_USER_STORAGE"
  14.     ], 
  15.      
  16. ······ 

Ability動態請求權限

  1. public class MainAbility extends Ability { 
  2.  
  3.     private String[] requestPermissions = { 
  4.             SystemPermission.WRITE_USER_STORAGE,  
  5.             SystemPermission.READ_USER_STORAGE,  
  6.             SystemPermission.LOCATION 
  7.     }; 
  8.  
  9.     @Override 
  10.     public void onStart(Intent intent) { 
  11.         super.onStart(intent); 
  12.         super.setMainRoute(MainAbilitySlice.class.getName()); 
  13.         PermissionsUtils.getInstance().requestPermissions(this, requestPermissions); 
  14.     } 
  15.  
  16.     @Override 
  17.     public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) { 
  18.         PermissionsUtils.getInstance().onRequestPermissionsResult(requestCode, permissions, grantResults); 
  19.     } 

啟動多點觸控手勢

  1. // 啟動多點觸控放大縮小旋轉 
  2. MapView.setMultiTouchControls(true); 

設置地圖中心點

  1. mMapController = mapView.getController(); 
  2. //設置地圖中心點位置 
  3. mMapController.setCenter(new GeoPoint(28.222567, 112.884651)); 

設置地圖縮放級別

  1. mMapController = mapView.getController(); 
  2. //設置初始化縮放級別 
  3. mMapController.setZoom(15.0); 

離線地圖加載

  1. //加載離線地圖 
  2. File file = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getParentFile(); 
  3. String strFilepath = file.getPath() + "/osmdroid/"
  4.  
  5. File[] files = new File(strFilepath).listFiles(); 
  6. if (files != null && files.length > 0) { 
  7.     File exitFile = files[0]; 
  8.     if (exitFile.exists()) { 
  9.         String filename = exitFile.getName(); 
  10.         String extension = filename.substring(filename.lastIndexOf(".") + 1); 
  11.         if (ArchiveFileFactory.isFileExtensionRegistered(extension)) { 
  12.             IRegisterReceiver registerReceiver = new SimpleRegisterReceiver(this); 
  13.             File[] offlineFiles = new File[]{exitFile}; 
  14.             OfflineTileProvider tileProvider = new OfflineTileProvider(registerReceiver, offlineFiles); 
  15.             mapView.setTileProvider(tileProvider); 
  16.  
  17.             IArchiveFile[] archives = tileProvider.getArchives(); 
  18.             if (archives.length > 0) { 
  19.                 Set<String> tileSource = archives[0].getTileSources(); 
  20.                 if (!tileSource.isEmpty()) { 
  21.                     String source = tileSource.iterator().next(); 
  22.                     mapView.setTileSource(FileBasedTileSource.getSource(source)); 
  23.                     mapView.setUseDataConnection(false); 
  24.                 } 
  25.             } 
  26.         } 
  27.     } 

添加覆蓋物

添加指南針

  1. //指南針 
  2. InternalCompassOrientationProvider compassProvider = new InternalCompassOrientationProvider(this); 
  3. CompassOverlay mCompassOverlay = new CompassOverlay(this, compassProvider, mapView); 
  4. mCompassOverlay.enableCompass(); 
  5. mapView.getOverlays().add(mCompassOverlay); 

添加我的定位點

  1. private MapView mapView; 
  2. private MyLocationNewOverlay mLocationOverlay; 
  3.  
  4. @Override 
  5. public void onStart(Intent intent) { 
  6.     super.onStart(intent); 
  7.     super.setUIContent(ResourceTable.Layout_ability_main); 
  8.  
  9.     if (isGrantedLocationPermission()) { 
  10.         addMyLocationOverlayMark(); 
  11.     } else { 
  12.         PermissionsUtils.getInstance().setRequestListener(permission -> { 
  13.             if (permission.equals(SystemPermission.LOCATION)) { 
  14.                 addMyLocationOverlayMark(); 
  15.             } 
  16.         }); 
  17.     } 
  18.  
  19. @Override 
  20. public void onActive() { 
  21.     super.onActive(); 
  22.     mapView.onResume(); 
  23.     if (mLocationOverlay != null) { 
  24.         mLocationOverlay.enableMyLocation(); 
  25.     } 
  26.  
  27. @Override 
  28. protected void onInactive() { 
  29.     super.onInactive(); 
  30.     mapView.onPause(); 
  31.     if (mLocationOverlay != null) { 
  32.         mLocationOverlay.disableMyLocation(); 
  33.     } 
  34.      
  35. private boolean isGrantedLocationPermission() { 
  36.     return IBundleManager.PERMISSION_GRANTED  
  37.         == verifyCallingOrSelfPermission(SystemPermission.LOCATION); 
  38.  
  39. private void addMyLocationOverlayMark() { 
  40.     //添加當前設備自動定位點,需要先具有設備位置權限 
  41.     mLocationOverlay = new MyLocationNewOverlay(mapView); 
  42.     PixelMap personPixelMap = ResourceHelper.getPixmap(this, ResourceTable.Media_person); 
  43.     PixelMap directionPixelMap = ResourceHelper.getPixmap(this, ResourceTable.Media_loc); 
  44.     mLocationOverlay.setDirectionArrow(personPixelMap, directionPixelMap); 
  45.     mapView.getOverlays().add(mLocationOverlay); 
  46. }    

添加地圖比例尺

  1. //添加比例尺 
  2. ScaleBarOverlay scaleBar = new ScaleBarOverlay(mapView); 
  3. scaleBar.setCentred(true); 
  4. scaleBar.setAlignBottom(true); //底部顯示 
  5. mapView.getOverlays().add(scaleBar); 

添加地圖自由旋轉

  1. //地圖自由旋轉 
  2. RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mapView); 
  3. mRotationGestureOverlay.setEnabled(true); 
  4. mapView.getOverlays().add(mRotationGestureOverlay); 

添加路徑規劃線路點

  1. //路徑規劃點 
  2. Polyline polyline = new Polyline(); 
  3.  
  4. //添加路徑上的關鍵坐標點 
  5. for(int i = 0; i < size; i++) { 
  6.     polyline.addPoint(new GeoPoint(latitude, longitude)); 
  7.  
  8. //設置信息框標題 
  9. polyline.setTitle("title"); 
  10. //設置信息框內容 
  11. polyline.setSubDescription(polyline.getDistance() + ""); 
  12. //設置線寬度為50 
  13. polyline.getOutlinePaint().setStrokeWidth(20); 
  14. //設置線的顏色為紅色 
  15. polyline.getOutlinePaint().setColor(Color.BLUE); 
  16. polyline.setInfoWindow(new BasicInfoWindow(ResourceTable.Layout_bonuspack_bubble, mapeView)); 
  17. mapView.getOverlayManager().add(polyline); 

碼云倉庫地址

https://gitee.com/talkwebyunchaung/osmdroid-ohos

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com

 

責任編輯:jianghua 來源: 鴻蒙社區
相關推薦

2020-12-23 11:36:23

鴻蒙HarmonyOS應用程序開發

2024-11-14 13:11:42

2009-04-23 17:37:05

LinuxRed Hat開源

2013-05-16 14:31:49

GoogleGoogle Maps

2021-06-15 14:33:00

高德百度騰訊

2020-12-07 12:34:33

開發板鴻蒙hello world

2010-08-18 09:43:55

光纜

2015-08-07 09:55:25

Windows安卓iOS移植

2021-03-18 08:11:18

PythonDash工具

2012-05-16 18:21:27

2012-06-25 09:55:53

諾基亞地圖Windows Pho

2012-09-18 13:13:17

2012-11-27 10:07:24

eWeek諾基亞Here地圖

2011-09-29 11:00:54

百度地圖API

2024-05-28 07:06:44

2015-05-18 16:53:36

Android

2009-12-07 09:32:44

WCF開源

2013-05-31 10:33:51

2012-12-18 09:51:53

谷歌地圖蘋果地圖

2011-09-16 10:37:42

地圖API
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美 日韩 国产 成人 | 999久久久| 久草在线影 | 欧美在线播放一区 | 日韩小视频在线 | 免费在线看黄视频 | 四虎影院免费在线 | 99色在线 | 91资源在线 | 欧美亚洲高清 | 一级黄片一级毛片 | 国产激情免费视频 | 成人免费观看男女羞羞视频 | 久久国产日韩欧美 | 99久久精品国产一区二区三区 | 亚洲福利一区 | 日韩综合网| 久色网 | 99视频在线 | 中文字幕一区二区三区不卡 | 国产成人aⅴ | 国产精品久久 | 久久久久久久91 | 欧美 日韩 中文 | 狠狠操你| 精品1区| 日本不卡一区二区 | 久草精品视频 | 一区二区三区观看视频 | 一区亚洲| 欧美日一区 | 久久久精| 日韩精品一区二区三区在线播放 | 手机三级电影 | 国产99久久精品一区二区永久免费 | 成人av免费 | 日本成人中文字幕在线观看 | 成人精品毛片 | 欧美福利 | 91av在线免费 | 日韩精品一区二区三区中文字幕 |