Android Programming Tutorials

(Romina) #1
Here a Post, There a Post

Step #2: Create a Basic MapActivity


Next, we need to create a stub MapActivity implementation that we can


then use in Patchy.


Create Patchy/res/layout/status_map.xml with the following content:


<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="00yHj0k7_7vxbuQ9zwyXI4bNMJrAjYrJ9KKHgbQ"
android:clickable="true" />

Note that you will need to substitute your API key for the one shown in


android:apiKey in the above code listing.


Next, create Patchy/src/apt/tutorial/two/StatusMap.java with the following


content:


package apt.tutorial.two;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class StatusMap extends MapActivity {
private MapView map=null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.status_map);

map=(MapView)findViewById(R.id.map);

map.getController().setZoom( 17 );
}

@Override
protected boolean isRouteDisplayed() {
return(false);

236
Free download pdf