Offline | Android Plugins - Mapbox
文章推薦指數: 80 %
The Maps SDK v10 and higher comes with offline functionality built in. See the Offline guide. The Offline Plugin for Android allows you to provide a seamless ... Youareusinganoutdatedbrowserandwillencountersomeproblemswithourwebsite.Pleaseconsiderupgrading.UpgradeNowLegacyThisfeatureisnolongerinactivedevelopment.AndroidPluginsSearchGuidesExamplesAPIReferenceAlldocsAndroidPluginsGuidesOfflineOfflineOnthispageInstalltheOfflinePluginAddthedependencyAddtheOfflinePluginOfflinetileestimatorShareyourfeedbackNotcompatiblewiththeMapsSDKv10ThispluginisnotcompatiblewiththeMapsSDKv10orhigher.TheMapsSDKv10andhighercomeswithofflinefunctionalitybuiltin.SeetheOfflineguide.TheOfflinePluginforAndroidallowsyoutoprovideaseamlessexperiencetoyourusersevenwhentheirdevicesdon'thaveastrongenoughinternetconnectiontodownloadandviewmaptiles.ThispluginoffersaconvenientwaytosendinformationtotheMapsSDK'sOfflineManagerclassandusethemanagerinabackgroundservicetodownloadmaptilesforofflineuse.Onceyoudefineandinitializetheofflinedownloadregion,thepluginhandleseverythingelseforyou.Becausethepluginusesaservice,itwillcontinuetodownloadmapdataevenifyourapplicationisrunninginthebackground.FormoreinformationabouthowtheMapboxMapsSDKforAndroidhandlesofflinemapping,seeourofflineguide.InstalltheOfflinePluginTostartdevelopinganapplicationusingtheOfflinePlugin,you'llneedtoaddtheappropriatedependenciesinsideofyourbuild.gradlefile.ThisdependencyincludestheMapsSDKforAndroid.YoucanfindalldependenciesgivenbelowonMavenCentral.Android's64KmethodcountlimitIfyourapplicationisoverthe64Kmethodlimit,youcanshrink,obfuscate,andoptimizeyourcodewithR8orProGuard.Ifthosestepsdonotloweryourmethodcountbelow64K,youcanalsoenablemultidex.AddthedependencyToinstalltheofflineplugin,headovertotheMapboxPluginOverviewpagewhichwillwalkyouthroughaddingthedependency.StartAndroidStudio.Openupyourapplication'sbuild.gradlefile.Makesurethatyourproject'sminSdkVersionisAPI14orhigher.Underdependencies,addanewbuildruleforthelatestmapbox-android-plugin-offline-v9.repositories{ mavenCentral() } dependencies{ implementation'com.mapbox.mapboxsdk:mapbox-android-plugin-offline-v9:0.8.0' } ClicktheSyncProjectwithGradleFilesnearthetoolbarinStudio.AddtheOfflinePluginTheOfflinePluginrequiresnopermissionsandisinitializedbyeventuallypassinginabuiltOfflineDownloadOptionsobject.Butbeforeyoudothat,you'llwanttodefinethemapregionthatyouwanttodownload.JavaKotlin//DefineregionofmaptilesOfflineTilePyramidRegionDefinitiondefinition=newOfflineTilePyramidRegionDefinition(styleUrl,newLatLngBounds.Builder().include(newLatLng(latitudeNorth,longitudeEast)).include(newLatLng(latitudeSouth,longitudeWest)).build(),minZoom,maxZoom,getResources().getDisplayMetrics().density);CopyBuildaNotificationOptionsobjectifyouwanttoshowsomesortofnotificationatthetopofthedevice'sscreenduringthedownload.JavaKotlin//Customizethedownloadnotification'sappearanceNotificationOptionsnotificationOptions=NotificationOptions.builder(this).smallIconRes(R.drawable.mapbox_logo_icon).returnActivity(MainActivity.class.getName()).build();CopyFinally,starttheactualdownloadofthemaptiles.TheNotificationsOptionsobjectisrequiredtostartthedownload.JavaKotlin//StartdownloadingthemaptilesforofflineuseOfflinePlugin.getInstance(this).startDownload( OfflineDownloadOptions.builder() .definition(definition) .metadata(OfflineUtils.convertRegionName(regionName)) .notificationOptions(notificationOptions) .build());CopyOfflinetileestimatorAnappcandownloadmultipleregionsforofflineuse,butthetotalofflinedownloadiscappedatamaximumtilecount“ceiling”acrossalldownloadedregions.Thepluginsetthetileceilingto6,000tiles.UseourTileCountEstimatortocalculatethenumberoftilesrequiredforyourofflineusecase.SixthousandtilescoveraregionroughlythesizeofGreaterLondonwithintheM25atzoomlevels0–15orthecontiguousUnitedStatesatzoomlevels0–9.Thesizeofthesetilesondiskwillvaryaccordingtotheselectedstyle.Shareyourfeedback
延伸文章資訊
- 1Migrate to v10 | Maps SDK | iOS | Mapbox
Upgrade your application from the Mapbox Maps SDK for iOS v6 to v10. ... The OfflineManager API c...
- 2Offline manager | Maps SDK v9 | Android | Mapbox
This page uses v9.7.1 of the Mapbox Maps SDK. A newer version of the SDK is available. Learn abou...
- 3Offline maps | Help | Mapbox
4.1 of the Mapbox Maps SDK for iOS. A newer version of the SDK is available. Learn about the late...
- 4Migrate to v10 | Maps SDK | Android | Mapbox
Upgrade your application from the Mapbox Maps SDK for Android v9 to v10. ... Read more about Offl...
- 5Download an offline map | Maps SDK v6 | iOS | Mapbox
This page uses v6.4.1 of the Mapbox Maps SDK. A newer version of the SDK is available. Learn abou...