Skip to content

Instantly share code, notes, and snippets.

@maptiler
Last active March 30, 2022 19:19
Show Gist options
  • Save maptiler/e15c4692b16af6de243c0a5ee556f5b3 to your computer and use it in GitHub Desktop.
Save maptiler/e15c4692b16af6de243c0a5ee556f5b3 to your computer and use it in GitHub Desktop.
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