Skip to content

Instantly share code, notes, and snippets.

@maptiler
Last active Mar 30, 2022
Embed
What would you like to do?
MapTiler Maps on Android Mapbox SDK
public class MyMapActivity extends Activity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, null); /* No need for any key here */
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
/* Get your a link to Vector Style JSON at https://cloud.maptiler.com/maps/streets/ */
String url = "https://api.maptiler.com/maps/streets/style.json?key=[get_your_own_key]";
Style.Builder builder = new Style.Builder().fromUri(url);
mapboxMap.setStyle(builder, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
}
});
}
});
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment