自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

鴻蒙開(kāi)源地圖,OSMDroid地圖項(xiàng)目移植到鴻蒙上

開(kāi)源
OSMDroid-ohos是Google開(kāi)源地圖項(xiàng)目OSMDroid移植到HarmonyOS系統(tǒng)上的精簡(jiǎn)版,可以實(shí)現(xiàn)在HarmonyOS系統(tǒng)上做地圖應(yīng)用開(kāi)發(fā)。當(dāng)前OSMDroid-ohos地圖根據(jù)國(guó)內(nèi)開(kāi)發(fā)情況,默認(rèn)移植了高德的瓦片地圖顯示。

[[414372]]

想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

OSMDroid-ohos

介紹

OSMDroid-ohos是Google開(kāi)源地圖項(xiàng)目OSMDroid移植到HarmonyOS系統(tǒng)上的精簡(jiǎn)版,可以實(shí)現(xiàn)在HarmonyOS系統(tǒng)上做地圖應(yīng)用開(kāi)發(fā)。當(dāng)前OSMDroid-ohos地圖根據(jù)國(guó)內(nèi)開(kāi)發(fā)情況,默認(rèn)移植了高德的瓦片地圖顯示。

OSMDroid-ohos地圖提供基本瓦片地圖顯示,地圖指南針覆蓋物,地圖定位坐標(biāo)覆蓋物,提供單指手勢(shì)拖拽地圖功能,單指手勢(shì)雙擊放大地圖功能,雙指手勢(shì)縮放地圖功能,雙指手勢(shì)旋轉(zhuǎn)地圖功能。

鴻蒙開(kāi)源地圖,OSMDroid地圖項(xiàng)目移植到鴻蒙上-鴻蒙HarmonyOS技術(shù)社區(qū)
鴻蒙開(kāi)源地圖,OSMDroid地圖項(xiàng)目移植到鴻蒙上-鴻蒙HarmonyOS技術(shù)社區(qū)

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. //實(shí)例化MapView 
  7. mapView = new MapView(this); 
  8. mMapContainerView.addComponent(mapView, 0, layoutConfig); 

請(qǐng)求相應(yīng)權(quán)限

config.json配置文件添加權(quán)限

  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動(dòng)態(tài)請(qǐng)求權(quán)限

  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.     } 

啟動(dòng)多點(diǎn)觸控手勢(shì)

  1. // 啟動(dòng)多點(diǎn)觸控放大縮小旋轉(zhuǎn) 
  2. MapView.setMultiTouchControls(true); 

設(shè)置地圖中心點(diǎn)

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

設(shè)置地圖縮放級(jí)別

  1. mMapController = mapView.getController(); 
  2. //設(shè)置初始化縮放級(jí)別 
  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); 

添加我的定位點(diǎn)

  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.     //添加當(dāng)前設(shè)備自動(dòng)定位點(diǎn),需要先具有設(shè)備位置權(quán)限 
  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); 

添加地圖自由旋轉(zhuǎn)

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

添加路徑規(guī)劃線路點(diǎn)

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

碼云倉(cāng)庫(kù)地址

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

想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

 

責(zé)任編輯:jianghua 來(lái)源: 鴻蒙社區(qū)
相關(guān)推薦

2020-12-23 11:36:23

鴻蒙HarmonyOS應(yīng)用程序開(kāi)發(fā)

2024-11-14 13:11:42

2009-04-23 17:37:05

LinuxRed Hat開(kāi)源

2021-06-15 14:33:00

高德百度騰訊

2013-05-16 14:31:49

GoogleGoogle Maps

2010-08-18 09:43:55

光纜

2020-12-07 12:34:33

開(kāi)發(fā)板鴻蒙hello world

2021-03-18 08:11:18

PythonDash工具

2015-08-07 09:55:25

Windows安卓iOS移植

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

2012-05-16 18:21:27

2013-05-31 10:33:51

2012-12-18 09:51:53

谷歌地圖蘋果地圖

2011-09-16 10:37:42

地圖API

2015-05-18 16:53:36

Android

2024-05-28 07:06:44

2009-12-07 09:32:44

WCF開(kāi)源
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)