Google

Monday, July 12, 2010

Android Google Map API programming - Easy Zoom



The above map implementation is easier than the previous post. It uses the built-in zoom (at bottom of screen) capability of Google Map API.


The main Activity class:
 package com.mvez;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.app.Activity;
import android.os.Bundle;
public class MapViewEasierZoom extends MapActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
@Override
protected boolean isLocationDisplayed() {
return false;
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}

The mapview.xml layout. Be sure to substitute your map api key in place of XXXXX:

 <?xml version="1.0" encoding="utf-8"?>
<!-- This file is /res/layout/mapview.xml -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:apiKey="XXXXXXXXXXXXXXXXXXXXXXXXXX"
/>
</RelativeLayout>