CS185c
Chris Pollett
May 7, 2012
<uses-library android:name="com.google.android.maps" /> <uses-permission android:name="android.permission.INTERNET" />
<activity android:name=".HelloMap" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
The main layout for our app is pretty simple:
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Your Maps API Key goes here"
/>
keytool -list -alias androiddebugkey \ -keystore ~/.android/debug.keystore \ -storepass android -keypass androidReplace in the above your path to debug.keystore
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class HelloMapActivity extends MapActivity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
Which of the following is true?
public class HelloItemizedOverlay extends ItemizedOverlay
{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
//this sets the center point of the marker at its bottom.
super(boundCenterBottom(defaultMarker));
//save so can use to handle touch events
mContext = context;
}
// this method is used to add overlays to our array list
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate(); // used to read each overlay item and prepare for drawing
}
// this method is called by populate
// needs to correctly get the overlay from our array list
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
// need to correctly say the size of our array list
@Override
public int size() {
return mOverlays.size();
}
// now we set up an Alert to display if the overlay is tapped.
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker); HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this); //next we create a marker and add it to our itemizedoverlay object GeoPoint point = new GeoPoint(19240000,-99120000); OverlayItem overlayitem = new OverlayItem(point, "Hello World", "Mexico City"); itemizedoverlay.addOverlay(overlayitem); GeoPoint point2 = new GeoPoint(35410000, 139460000); OverlayItem overlayitem2 = new OverlayItem(point2, "Sekai, konichiwa!", "I'm in Japan!"); itemizedoverlay.addOverlay(overlayitem2); mapOverlays.add(itemizedoverlay);
controller = mapView.getController();
String coordinates[] = {"1.5", "103.6"};
double latitude = Double.parseDouble(coordinates[0]);
double longitude = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
controller.animateTo(p);
controller.setZoom(17);
mapView.invalidate();