Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccabanero/e9e8f04f74ea9c76c248 to your computer and use it in GitHub Desktop.
Save ccabanero/e9e8f04f74ea9c76c248 to your computer and use it in GitHub Desktop.
Getting started with Mapbox Android SDK (version 3.2.0)
Description:
Steps for Getting Started with the Mapbox Android SDK (v 3.2)
1. Create a new project in Android Studio (1.5.1) (e.g. Empty Activity or Blank Activity template)
2. Installation via Gradle:
Added the following to the root ...
repositories {
mavenCentral()
}
Added the following to the dependencies element ...
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:3.2.0@aar'){
transitive=true
}
3. Manifest
Add needed permsission for example:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
4. Strings
Added the follwing in app/res/values/strings.xml ...
<!-- Access Token -->
<string name="accessToken" translatable="false">pk.blablabla.bla</string>
5. Layout
Added the following to the layout file ...
- xmlns:mapbox
- mapView
See below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.yuh.sucks.MainActivity">
<com.mapbox.mapboxsdk.views.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapbox:access_token="@string/accessToken"/>
</RelativeLayout>
6. Activity
In Activity class, needed to call mapView.onCreate(). See below ...
public class MainActivity extends AppCompatActivity {
private MapView mv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mv = (MapView) findViewById(R.id.mapview);
mv.setStyle(Style.MAPBOX_STREETS);
mv.onCreate(savedInstanceState);
}
}
NOTES FOR USING THE OFFLINE SNAPSHOT
1. Gradle
Changed the relevant sections - such as:
repositories {
mavenCentral()
// added this
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
// changed here
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:4.0.0-SNAPSHOT@aar'){
transitive=true
}
}
2. Activity
Changed the import for MapView to:
import com.mapbox.mapboxsdk.maps.MapView;
3. Layout
Changed the xml for layout to use com.mapbox.mapboxsdk.maps.MapView:
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapbox:access_token="@string/accessToken"/>
4. Manifest
Needed to add com.mapbox.mapboxsdk.telemetry.TelemetryService
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment