Select to view content in your preferred language

Local Mbtiles sample for Android SDK

4630
1
Jump to solution
12-12-2014 07:18 AM
Jean-JacquesMONOT
Deactivated User

Hello

 

I have tried to use directly the sample Local Mbtiles for the Android SDK (https://developers.arcgis.com/android/sample-code/local-mbtiles/).

 

With no modification of the class :

- Compilation done with Eclipse ADT : OK, but when launched on the smartphone, I get a direct crash.

- Transposed in Android Studio (taking care of course of librairies and gradle build options .... ) : compilation OK, but same phenomena (crash at launch).

 

So I modified the main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

   

    <!-- MapView layout and initial extent -->

    <com.esri.android.map.MapView

          android:id="@+id/map"

          android:layout_width="fill_parent"

          android:layout_height="fill_parent"

        mapoptions.Center="49.0, 2.0"

        mapoptions.MapType="Topo"

        mapoptions.ZoomLevel="16"

          >

      </com.esri.android.map.MapView>

     

</LinearLayout>

 

And put in comment the connexion to ArcGISTiledMapServiceLayer, my file sample.mbtiles, the map does not appear .... ?!?

 

The application is not crashing any more, but parsing of the mbtiles file does not work? This is a real mbtiles file, displayed with no problem with Locus on the smartphone.

 

/* Copyright 2014 ESRI

*

* All rights reserved under the copyright laws of the United States

* and applicable international laws, treaties, and conventions.

*

* You may freely redistribute and use this sample code, with or

* without modification, provided you include the original copyright

* notice and use restrictions.

*

* See the Sample code usage restrictions document for further information.

*

*/

 

package com.esri.android.samples.mbtiles;

 

import android.app.Activity;

import android.content.Context;

import android.net.ConnectivityManager;

import android.net.NetworkInfo;

import android.os.Bundle;

import android.os.Environment;

import android.widget.Toast;

 

import com.esri.android.map.MapView;

import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;

 

public class LocalMBTiles extends Activity {

  MapView mMapView = null;

  ArcGISTiledMapServiceLayer tileLayer;

  boolean activeNetwork;

 

  @Override

  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

 

    // Retrieve the map and initial extent from XML layout

    mMapView = (MapView) findViewById(R.id.map);

 

    // create an ArcGISTiledMapServiceLayer as a background if network available

//    activeNetwork = isNetworkAvailable();

//    if (activeNetwork) {

//      tileLayer = new ArcGISTiledMapServiceLayer(

//          "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");

//      // Add tiled layer to MapView

//      mMapView.addLayer(tileLayer);

//    }else{

//      Toast toast = Toast.makeText(this, R.string.offline_message, Toast.LENGTH_SHORT);

//      toast.show();

//    }

 

    // Add a MBTilesLayer on top with 50% opacity

    MBTilesLayer mbLayer = new MBTilesLayer(Environment.getExternalStorageDirectory().getPath()

        + "/sample.mbtiles");

    Toast.makeText(getApplicationContext(),Environment.getExternalStorageDirectory().getPath()

            + "/sample.mbtiles", Toast.LENGTH_LONG).show();

 

 

    //mbLayer.setOpacity(0.5f);

    mMapView.addLayer(mbLayer);

    // enable map to wrap around

    mMapView.enableWrapAround(true);

    mMapView.centerAt(49.0,2.0,true);

 

 

  }

 

  private boolean isNetworkAvailable() {

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();

 

    if (netInfo != null && netInfo.isConnected()) {

      return true;

    }

 

    return false;

  }

 

  @Override

  protected void onPause() {

    super.onPause();

    mMapView.pause();

  }

 

  @Override

  protected void onResume() {

    super.onResume();

    mMapView.unpause();

  }

 

}

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Jean-JacquesMONOT
Deactivated User

I have found my "problem". Thé sdk takes into account the bounds for request to thé mbtiles file.

My bounds were too much small and no request were sent by the API.

View solution in original post

0 Kudos
1 Reply
Jean-JacquesMONOT
Deactivated User

I have found my "problem". Thé sdk takes into account the bounds for request to thé mbtiles file.

My bounds were too much small and no request were sent by the API.

0 Kudos