sample code - maps

satya - Sunday, September 28, 2008 11:15:31 AM

Maps, menus, key events


import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Vector;
import org.apache.http.protocol.HTTP;
import android.os.Bundle;
import android.view.*;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;


public class prueba extends MapActivity {

       MapView map;
          GeoPoint Point = new GeoPoint((int) (-1.416402 * 1000000), (int)
              (-78.025078 * 1000000));
           @Override
           public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.main);
               map = (MapView) findViewById(R.id.map);
               map.getController().setCenter(Point);
            //  map.getController().animateTo(Point);
               map.displayZoomControls(false);
               map.getController().setZoom(7);
            }
       public boolean onKeyDown(int keyCode, KeyEvent event) {
               switch(keyCode){
               case KeyEvent.KEYCODE_I:
                       int level = map.getZoomLevel();
           map.getController().setZoom(level + 1);
                       return true;
               case KeyEvent.KEYCODE_O:
                       int level2 = map.getZoomLevel();
           map.getController().setZoom(level2 + 1);
                       return true;
               case KeyEvent.KEYCODE_S:
                       map.setSatellite(true);
                       return true;
               case KeyEvent.KEYCODE_T:
                       map.setSatellite(false);
                       return true;
               }
               return false;
       }

       @Override
       public boolean onCreateOptionsMenu(Menu menu) {
       super.onCreateOptionsMenu(menu);
               menu.add(0,1,2, "My Location");
               //menu 1
               SubMenu sub1 = menu.addSubMenu(3, 2, 3,"Vistas");
               sub1.add(3,3,1, "Satelite");
               sub1.add(3,4,2, "Trafico");
               //menu 2
               SubMenu sub = menu.addSubMenu(2, 5, 1,"Zoom");
               sub.add(2,6,1, "In");
               sub.add(2,7,2, "Out");
               return true;
       }
       @Override
       public boolean onMenuItemSelected(int featureId, MenuItem item) {
       super.onMenuItemSelected(featureId, item);
       switch (item.getItemId()) {
       case 1:

       return true;
       case 3:
               map.setSatellite(true);
       return true;
       case 4:
               map.setSatellite(false);
       return true;
       case 6:
               int level = map.getZoomLevel();
           map.getController().setZoom(level + 1);
       return true;
       case 7:
               int level1 = map.getZoomLevel();
           map.getController().setZoom(level1 - 1);
       return true;
    }
    return super.onOptionsItemSelected(item);
  }
       @Override
       protected boolean isRouteDisplayed() {
               // TODO Auto-generated method stub
               return false;
       }
}

satya - Sunday, September 28, 2008 11:17:02 AM

Borrowed from a post from Jordan Innovations

Borrowed from a post from Jordan Innovations