Offline | Android Plugins - Mapbox

文章推薦指數: 80 %
投票人數:10人

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



請為這篇文章評分?