MyMap.java
上传用户:xmjingguan
上传日期:2009-07-06
资源大小:2054k
文件大小:2k
- /***
- * Excerpted from "Hello, Android!",
- * published by The Pragmatic Bookshelf.
- * Copyrights apply to this code. It may not be used to create training material,
- * courses, books, articles, and the like. Contact us if you are in doubt.
- * We make no guarantees that this code is fit for any purpose.
- * Visit http://www.pragmaticprogrammer.com/titles/eband for more book information.
- ***/
- package org.example.mymap;
- import android.os.Bundle;
- import com.google.android.maps.MapActivity;
- import com.google.android.maps.MapController;
- import com.google.android.maps.MapView;
- import com.google.android.maps.MyLocationOverlay;
- public class MyMap extends MapActivity {
- private MapView map;
- private MapController controller;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- initMapView();
- initMyLocation();
- }
-
-
- /** Find and initialize the map view. */
- private void initMapView() {
- map = (MapView) findViewById(R.id.map);
- controller = map.getController();
- map.setSatellite(true);
- map.setBuiltInZoomControls(true);
- }
-
-
- /** Start tracking the position on the map. */
- private void initMyLocation() {
- final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
- overlay.enableMyLocation();
- //overlay.enableCompass(); // does not work in emulator
- overlay.runOnFirstFix(new Runnable() {
- public void run() {
- // Zoom in to current location
- controller.setZoom(8);
- controller.animateTo(overlay.getMyLocation());
- }
- });
- map.getOverlays().add(overlay);
- }
-
-
- @Override
- protected boolean isRouteDisplayed() {
- // Required by MapActivity
- return false;
- }
- }