マピオンAPI


Android Maps APIドキュメント

地図の種類を変更する

res/drawableにlightblue.pngを入れておくこと

public class MainActivity extends MapActivity {

	MapView mapView;
	
	Map standardMap;
	Map lightMap;
	Map textureMap;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		standardMap = new StandardMap("APIキー");
		lightMap = new LightMap("APIキー");
		textureMap = new TextureMap("APIキー");
		
		LinearLayout layout = new LinearLayout(this);
		setContentView(layout);
		layout.setOrientation(LinearLayout.VERTICAL);

		mapView = new MapView(this, standardMap);
		mapView.setClickable(true);
		
		mapView.setBuiltInZoomControls(true);

		LinearLayout layout2 = new LinearLayout(this);
		layout2.setOrientation(LinearLayout.HORIZONTAL);
		layout.addView(layout2, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
		
		
		Button button = new Button(this);
		button.setText("3D風地図");
		button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mapView.getController().changeMap(textureMap);
			}
		});
		layout2.addView(button, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
		
		Button button2 = new Button(this);
		button2.setText("軽量地図");
		button2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mapView.getController().changeMap(lightMap);
			}
		});
		layout2.addView(button2, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

		Button button3 = new Button(this);
		button3.setText("標準地図");
		button3.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mapView.getController().changeMap(standardMap);
			}
		});
		layout2.addView(button3, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
		
		layout.addView(mapView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
	}
}