Basic Map-Application
This tutorial is updated, but working solutions can be found in the responses!
This tutorial is updated, but working solutions can be found in the responses!
What is this: This tutorial shows how to extend the MapActivity to create relatively sophisticated applications in very short time.
What you learn: You will learn how to extend the MapActivity to create Map-Applications.
Difficulty: 1 of 5

What it will look like: (Statue of Liberty, Eiffeltower, Broadway)

Description:
What we will do is, create a MapActivity(extend it) and setup a MapView-Object.
The Main steps are:
- 1. Setup MapView
1.1. Locate a positon and zoom
2. Toggle to sattelite mode
(3. register some key-events on the MapActivity(==on our whole app))
The Code
Using java Syntax Highlighting
- package org.anddev.android.basicmapapp;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import com.google.android.maps.MapActivity;
- import com.google.android.maps.MapController;
- import com.google.android.maps.MapView;
- import com.google.android.maps.Point;
- public class BasicMapApp extends MapActivity {
- private MapView myMapView;
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- myMapView = new MapView(this);
- // Lets start at the Statue of Liberty
- // I grabbed the data from Google-Maps
- Point p = new Point((int) (40.689213 * 1000000),
- (int) (-74.044558 * 1000000));
- // Get the controller, that is used for translation and zooming
- MapController mc = myMapView.getController();
- // Translate to the Statue of Liberty
- mc.animateTo(p);
- // Zoom Very close
- mc.zoomTo(21);
- // Make myMapView the exilicit view of this app
- setContentView(myMapView);
- // Enable Sattelite-Mode, so we will se the
- // Statue of liberty instantly on the screen
- myMapView.toggleSatellite();
- }
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_I) {
- // Zooming In
- myMapView.getController().zoomTo(myMapView.getZoomLevel() + 1);
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_O) {
- // Zooming Out
- myMapView.getController().zoomTo(myMapView.getZoomLevel() - 1);
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_S) {
- // Switch to satellite view
- myMapView.toggleSatellite();
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_T) {
- // Switch on traffic overlays
- myMapView.toggleTraffic();
- return true;
- }
- return false;
- }
- }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4









