2016-12-21 7 views
-2

Ich habe eine Anwendung in Android Studio erstellt und installieren Sie die SDK-Anwendung Und die Anwendung läuft normal, ohne Probleme, aber die Einrichtung der Karte ProgressBar geladen in die Mitte und steht und zeigt mir in den Betrieb dieses Satzes, dass ich die erforderlichen Flieseeinfaches Beispiel für mapbox offline in Android funktioniert nicht

dies XML

<com.mapbox.mapboxsdk.maps.MapView 
    android:id="@+id/mapView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    mapbox:center_latitude="37.73359" 
    mapbox:center_longitude="-119.58410" 
    mapbox:style_url="mapbox://styles/mapbox/outdoors-v9" 
    mapbox:zoom="10" 
    mapbox:zoom_min="10"/> 

<ProgressBar 
    android:id="@+id/progress_bar" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="match_parent" 
    android:layout_height="25dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerInParent="true" 
    android:paddingLeft="25dp" 
    android:paddingRight="25dp" 
    android:visibility="gone"/> 

überschritten haben diese

ist MainActivity

public class MainActivity extends AppCompatActivity { 
private static final String TAG = "MainActivity"; 

private boolean isEndNotified; 
private ProgressBar progressBar; 
private MapView mapView; 
private OfflineManager offlineManager; 

// JSON encoding/decoding 
public static final String JSON_CHARSET = "UTF-8"; 
public static final String JSON_FIELD_REGION_NAME = "FIELD_REGION_NAME"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // 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_main); 

    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(MainActivity.this); 

      // Create a bounding box for the offline region 
      LatLngBounds latLngBounds = new LatLngBounds.Builder() 
        .include(new LatLng(37.7897, -119.5073)) // Northeast 
        .include(new LatLng(37.6744, -119.6815)) // Southwest 
        .build(); 

      // Define the offline region 
      OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(
        mapView.getStyleUrl(), 
        latLngBounds, 
        10, 
        20, 
        MainActivity.this.getResources().getDisplayMetrics().density); 

      // Set the metadata 
      byte[] metadata; 
      try { 
       JSONObject jsonObject = new JSONObject(); 
       jsonObject.put(JSON_FIELD_REGION_NAME, "Yosemite National Park"); 
       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); 
         } 
        }); 
     } 
    }); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    mapView.onResume(); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    mapView.onPause(); 
    offlineManager.listOfflineRegions(new OfflineManager.ListOfflineRegionsCallback() { 
     @Override 
     public void onList(OfflineRegion[] offlineRegions) { 
      if (offlineRegions.length > 0) { 
       // delete the last item in the offlineRegions list which will be yosemite offline map 
       offlineRegions[(offlineRegions.length - 1)].delete(new OfflineRegion.OfflineRegionDeleteCallback() { 
        @Override 
        public void onDelete() { 
         Toast.makeText(MainActivity.this, "Yosemite offline map deleted", Toast.LENGTH_LONG).show(); 
        } 

        @Override 
        public void onError(String error) { 
         Log.e(TAG, "On Delete error: " + error); 
        } 
       }); 
      } 
     } 

     @Override 
     public void onError(String error) { 
      Log.e(TAG, "onListError: " + error); 
     } 
    }); 
} 

@Override 
public void onLowMemory() { 
    super.onLowMemory(); 
    mapView.onLowMemory(); 
} 

@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    mapView.onDestroy(); 
} 

@Override 
protected void onSaveInstanceState(Bundle outState) { 
    super.onSaveInstanceState(outState); 
    mapView.onSaveInstanceState(outState); 
} 

// Progress bar methods 
private void startProgress() { 

    // Start and show the progress bar 
    isEndNotified = false; 
    progressBar.setIndeterminate(true); 
    progressBar.setVisibility(View.VISIBLE); 
} 

private void setPercentage(final int percentage) { 
    progressBar.setIndeterminate(false); 
    progressBar.setProgress(percentage); 
} 

private void endProgress(final String message) { 
    // Don't notify more than once 
    if (isEndNotified) { 
     return; 
    } 

    // Stop and hide the progress bar 
    isEndNotified = true; 
    progressBar.setIndeterminate(false); 
    progressBar.setVisibility(View.GONE); 

    // Show a toast 
    Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show(); 
} 

}

this is problem

+0

Bitte fügen Sie die Protokolle des Problems, das Sie in der Beschreibung des Problems haben, ein. – dazza5000

+0

Mögliche Duplikate von [Wie mit Offline-Karte in Android] (http://stackoverflow.com/questions/40804868/how-using-offline-map-in-android) – dazza5000

Antwort

0

Dies ist kein Fehler, sondern eine Beschränkung wir auf Nutzer verhängen, so dass sie nicht alle der Erde zum Beispiel auf einmal herunterladen. Sie können mehr über die tile limit here lesen und die tile calculator verwenden, um die Region zu schätzen. Wenn Sie eine größere Region herunterladen möchten, müssen Sie Ihre Region in kleinere Downloads aufteilen.

Verwandte Themen