1
我想在我的應用程序中下載特定的城市。如何做到這一點?還有一個問題:當我使用Mapbox 4.1.1的SDK時,我無法添加類BoundingBox
。如何在Android中使用離線地圖
我有一個問題,code that exists on their site下載地圖不是基於一次。我必須停止運行程序,並且當我重新運行它時,地圖不會再次加載。 這是我的代碼:指定是超過6000瓦數限制
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
MapboxAccountManager.start(this, getString(R.string.access_token));
// This contains the MapView in XML and needs to be called after the account manager
setContentView(R.layout.activity_offline_simple);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
// Set up the OfflineManager
offlineManager = OfflineManager.getInstance(SimpleOfflineMapActivity.this);
// Create a bounding box for the offline region
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(13.1,32.6)) // Northeast
.include(new LatLng(13.6,32.9)) // Southwest
.build();
// Define the offline region
OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(
mapView.getStyleUrl(),
latLngBounds,
10,
20,
SimpleOfflineMapActivity.this.getResources().getDisplayMetrics().density);
// Set the metadata
byte[] metadata;
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put(JSON_FIELD_REGION_NAME, "Triopli Libya");
String json = jsonObject.toString();
metadata = json.getBytes(JSON_CHARSET);
} catch (Exception exception) {
Log.e(TAG, "Failed to encode metadata: " + exception.getMessage());
metadata = null;
}
// Create the region asynchronously
offlineManager.createOfflineRegion(
definition,
metadata,
new OfflineManager.CreateOfflineRegionCallback() {
@Override
public void onCreate(OfflineRegion offlineRegion) {
offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE);
// Display the download progress bar
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
startProgress();
// Monitor the download progress using setObserver
offlineRegion.setObserver(new OfflineRegion.OfflineRegionObserver() {
@Override
public void onStatusChanged(OfflineRegionStatus status) {
// Calculate the download percentage and update the progress bar
double percentage = status.getRequiredResourceCount() >= 0
? (100.0 * status.getCompletedResourceCount()/status.getRequiredResourceCount()) :
0.0;
if (status.isComplete()) {
// Download complete
endProgress("Region downloaded successfully.");
} else if (status.isRequiredResourceCountPrecise()) {
// Switch to determinate state
setPercentage((int) Math.round(percentage));
}
}
@Override
public void onError(OfflineRegionError error) {
// If an error occurs, print to logcat
Log.e(TAG, "onError reason: " + error.getReason());
Log.e(TAG, "onError message: " + error.getMessage());
}
@Override
public void mapboxTileCountLimitExceeded(long limit) {
// Notify if offline region exceeds maximum tile count
Log.e(TAG, "Mapbox tile count limit exceeded: " + limit);
}
});
}
@Override
public void onError(String error) {
Log.e(TAG, "Error: " + error);
}
});
}
});
}
OpenStreetMap你可以使用。 – Saveen
在用什麼? –
從這裏看看https://github.com/osmdroid/osmdroid – Saveen