Working with a 3D map
Working with maps in an Android application
Example API use
This example demonstrates a basic map embedded in an Activity. Any application which displays a map must include the following:
- Declaration of required Android permissions in
AndroidManifest.xml
- Initialization of the EegeoApi object with a WRLD API key
- Creation of the MapView object, either in a layout or in code
- Association of the MapView object with Activity lifecycle events
Full source code for all examples is available on GitHub.
package com.eegeo.apisamples;
import android.os.Bundle;
import android.widget.Toast;
import com.eegeo.mapapi.EegeoApi;
import com.eegeo.mapapi.EegeoMap;
import com.eegeo.mapapi.MapView;
import com.eegeo.mapapi.map.OnMapReadyCallback;
public class BasicMapActivity extends WrldExampleActivity {
private MapView m_mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialise the EegeoApi with your api key - this needs calling either in the application
// instance, or in the activity that contains the MapView
EegeoApi.init(this, getString(R.string.eegeo_api_key));
// The MapView is contained in a layout xml
setContentView(R.layout.basic_map_activity);
m_mapView = (MapView) findViewById(R.id.basic_mapview);
m_mapView.onCreate(savedInstanceState);
m_mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final EegeoMap map) {
Toast.makeText(BasicMapActivity.this, "Welcome to WRLD Maps", Toast.LENGTH_LONG).show();
}
});
}
@Override
protected void onResume() {
super.onResume();
m_mapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
m_mapView.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
m_mapView.onDestroy();
}
}