Display Maps (Android) Follow
This article describes how to display maps using the Android SDK.
Display Maps
You can use MapFragment to provide a self-contained interface for maps and directions. Simply initialize the fragment with a valid EditorKey:
// Create a key representing your app in the Meridian Editor. EditorKey appKey = new EditorKey("5809862863224832"); // Create a key representing a map in the Meridian Editor. EditorKey mapKey = EditorKey.forMap("5668600916475904", appKey.getId()); MapFragment mapFragment = new MapFragment.Builder().setMapKey(mapKey).build();
MapFragment hosts a MapView and implements the MapView.MapViewListener interface, handling the basic tasks delegated by MapView.
You can also use MapView directly in your own activity or fragment, optionally implementing methods defined by the MapView.MapViewListener interface so that your activity can respond to MapView events.
Call the setMapKey() method to choose the map to display.
NOTE: We strongly advise using MapFragment whenever possible. If you decide to use a MapView independently, you must always pass your activity’s pause/resume/destroy events to the MapView to ensure resources are managed properly.
// Using pause/resume/destroy events with a MapView in your activity private MapView mapView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EditorKey appKey = new EditorKey("5809862863224832"); mapView = new MapView(this);
mapView.setAppKey(appKey); // If you want to handle MapView events mapView.setMapEventListener(this); // Set the map to load mapView.setMapKey(EditorKey.forMap("5668600916475904", appKey.getId())); // Assume myLayout is this activity's root view myLayout.addView(mapView); } @Override protected void onResume() { super.onResume(); // MapView needs to know when its host activity is resumed mapView.onResume(); } @Override protected void onPause() { super.onPause(); // MapView needs to know when its host activity is paused mapView.onPause(); } @Override protected void onDestroy() { super.onDestroy(); // MapView needs to know when its host activity is destroyed (SDK 4.7.0 and above) mapView.onDestroy(); }
Comments
0 comments
Please sign in to leave a comment.