@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // Handles the menu item selection.
   switch (item.getItemId()) {
     case R.id.menu_satellite:
       mMapView.setSatellite(true);
       mMapView.setTraffic(false);
       return true;
     case R.id.menu_map:
       mMapView.setSatellite(false);
       return true;
     case R.id.menu_traffic:
       if (mMapView.isTraffic()) {
         mMapView.setTraffic(false);
       } else {
         mMapView.setTraffic(true);
         mMapView.setSatellite(false);
       }
       return true;
     case R.id.menu_help:
       showHelpDialog();
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
 /** @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) */
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case 0:
       // Zoom in
       zoomIn();
       return true;
     case 1:
       // Zoom out
       zoomOut();
       return true;
     case 2:
       // Toggle satellite views
       mvMap.setSatellite(!mvMap.isSatellite());
       return true;
     case 3:
       // Toggle street views
       mvMap.setStreetView(!mvMap.isStreetView());
       return true;
     case 4:
       // Toggle traffic views
       mvMap.setTraffic(!mvMap.isTraffic());
       return true;
     case 5:
       // Show the job list activity
       startActivity(new Intent(MicroJobs.this, MicroJobsList.class));
       return true;
   }
   return false;
 }
 /**
  * When traffic mode is clicked by the user.
  *
  * @param view The traffic view.
  */
 public void onTrafficModeClicked(View view) {
   if (mMapView.isTraffic()) {
     mMapView.setTraffic(false);
     mMapModeView.setEnabled(false);
     mSatelliteModeView.setEnabled(true);
   } else {
     // If Traffic mode is selected, show the traffic in Map Mode only.
     // If Map is already on satellite mode than automatically change it
     // to Map Mode and enable the traffic.
     mMapView.setTraffic(true);
     mMapView.setSatellite(false);
     mMapModeView.setEnabled(false);
     mTrafficModeView.setEnabled(false);
     mSatelliteModeView.setEnabled(true);
   }
 }
 /**
  * When satellite mode is clicked by the user.
  *
  * @param view The satellite view.
  */
 public void onSatModeClicked(View view) {
   mMapView.setSatellite(true);
   mMapView.setTraffic(false);
   view.setEnabled(false);
   mMapModeView.setEnabled(true);
   mTrafficModeView.setEnabled(true);
 }
Пример #5
0
 public boolean onKeyDown(int keyCode, KeyEvent e) {
   if (keyCode == KeyEvent.KEYCODE_S) {
     mapView.setSatellite(!mapView.isSatellite());
     return true;
   } else if (keyCode == KeyEvent.KEYCODE_T) {
     mapView.setTraffic(!mapView.isTraffic());
     mapControl.animateTo(gp); // To ensure change displays immediately
   }
   return (super.onKeyDown(keyCode, e));
 }
Пример #6
0
  private void updateMapView() {
    int intZoomLevel = 17;
    MapView mapView = (MapView) findViewById(0 /*R.id.map*/);
    mapController = mapView.getController();
    mapView.setSatellite(false);
    mapView.setStreetView(true);
    mapView.setTraffic(true);

    geoPoint = new GeoPoint((int) (dLat), (int) (dLng /* * 1E6*/)); // 將剛剛取得的座標置入geoPoint
    mapView.displayZoomControls(true);
    mapView.setBuiltInZoomControls(true);

    mapController.animateTo(geoPoint); // 將map的中心點移到自己所在的位置
    mapController.setZoom(intZoomLevel); // 設定地圖級距

    // 加入地圖標籤
    MyLocationOverlay mapOverlay = new MyLocationOverlay(context, mapView);
    List listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);
  }
Пример #7
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); // Suppress title bar to give more space
    setContentView(R.layout.show_the_map);

    initiateLocation();

    // Add map controller with zoom controls
    mapView = (MapView) findViewById(R.id.mv);
    mapView.setSatellite(true);
    mapView.setTraffic(false);
    mapView.setBuiltInZoomControls(true); // Set android:clickable=true in main.xml
    int maxZoom = mapView.getMaxZoomLevel();
    int initZoom = (int) (0.80 * (double) maxZoom);
    mapControl = mapView.getController();
    mapControl.setZoom(initZoom);
    // Convert lat/long in degrees into integers in microdegrees
    latE6 = (int) (lat * 1e6);
    lonE6 = (int) (lon * 1e6);
    gp = new GeoPoint(latE6, lonE6);
    mapControl.animateTo(gp);
  }
Пример #8
0
  public void init() {

    LogManager.d("init");

    geoBeijing = new GeoPoint((int) (39.932 * 1000000), (int) (116.461 * 1000000));
    mDefaultCurrentLocation =
        new GeoPoint((int) (41.892910 * 1000000), (int) (12.48251990 * 1000000));

    mapView = (MapView) findViewById(R.id.map_view);
    map_view_enable = findViewById(R.id.map_view_enable);
    mapView.getLayoutParams().height = BaseActivity.screen_height * 1 / 2;
    map_view_enable.getLayoutParams().height = BaseActivity.screen_height * 1 / 2;
    mapView.setOnTouchListener(this);
    mapView.setSaveEnabled(true);
    mapView.setBuiltInZoomControls(false);

    mapCon = mapView.getController();
    mapCon.setZoom(defaultZoom);

    // geo = new Geocoder(getContext(), Locale.CHINA);
    mapCon.setCenter(mDefaultCurrentLocation);
    mapView.setTraffic(false);
    mapView.setSatellite(false);

    mPopView = (ViewGroup) mapActivity.getLayoutInflater().inflate(R.layout.map_popover, null);

    // MapActivity mapActivity = (MapActivity)getContext();
    // WindowManager windowManager = mapActivity.getWindowManager();
    // int width = windowManager.getDefaultDisplay().getWidth();

    mapView.addView(
        mPopView,
        new MapView.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            null,
            MapView.LayoutParams.TOP_LEFT));
    mPopView.setVisibility(View.GONE);
    overlays = mapView.getOverlays();

    Drawable currentLocationMarker =
        this.getContext().getResources().getDrawable(R.drawable.user_location);
    mCurrentLocationOverlay = new MapItemizedOverlay(currentLocationMarker, this);
    mCurrentLocationOverlay.showPop = false;
    Drawable search = this.getContext().getResources().getDrawable(R.drawable.pin);

    bankOverlay = new MapItemizedOverlay(search, this);

    overlays.add(mCurrentLocationOverlay);
    overlays.add(bankOverlay);

    locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);

    mLocationListener1 =
        new LocationListener() {
          public void onLocationChanged(Location location) {
            Log.e(
                "Location",
                "GPSListener  "
                    + "latitude:"
                    + Double.toString(location.getLatitude())
                    + " longtitude:"
                    + Double.toString(location.getLongitude())
                    + " from:"
                    + location.getProvider());
            if (isBetterLocation(location, mCurrentLocation)) {
              setCurrentLocation(location);
              if (mMapShowingForLocationUpdate) {
                addCurrentLocationOverlay();
              }
            }
          }

          public void onStatusChanged(String provider, int status, Bundle extras) {}

          public void onProviderEnabled(String provider) {}

          public void onProviderDisabled(String provider) {}
        };

    mLocationListener2 =
        new LocationListener() {
          private boolean mFirstLaunch;

          public void onLocationChanged(Location location) {
            Log.e(
                "Location",
                "NetworkListener  "
                    + "latitude:"
                    + Double.toString(location.getLatitude())
                    + " longtitude:"
                    + Double.toString(location.getLongitude())
                    + " from:"
                    + location.getProvider());
            if (isBetterLocation(location, mCurrentLocation)) {
              setCurrentLocation(location);
              if (mMapShowingForLocationUpdate) {
                addCurrentLocationOverlay();
              }
            }
            if (mFirstLaunch == true) {
              mFirstLaunch = false;
              locationManager.removeUpdates(mLocationListener2);
            }
          }

          public void onStatusChanged(String provider, int status, Bundle extras) {}

          public void onProviderEnabled(String provider) {}

          public void onProviderDisabled(String provider) {}
        };
    myLocation = (ImageButton) findViewById(R.id.my_location);
    mapLayer = (ImageButton) findViewById(R.id.map_layer);
    showItems = (ImageButton) findViewById(R.id.show_items);
    searchButton = (ImageButton) findViewById(R.id.search_btn);
    searchEdt = (EditText) findViewById(R.id.search_input);
    distance_input = (EditText) findViewById(R.id.distance_input);
    if (App.app.initValue) {

      searchEdt.setText("05387");

      searchEdt.setText("via del tintoretto,200,roma");
    }

    searchButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // BaseMapActivity baseactivity = (BaseMapActivity)getContext();
            // baseactivity.hideKeyboard(searchButton);
            KeyBoardUtils.hideSoftInputFromWindow(mapActivity, searchEdt.getWindowToken());
            ProgressOverlay progressOverlay = new ProgressOverlay(getContext());
            progressOverlay.show(
                "searching...",
                new OnProgressEvent() {

                  @Override
                  public void onProgress() {

                    // Locale locale =
                    // getResources().getConfiguration().locale;

                    final String keyText = searchEdt.getText().toString();
                    searchGeoPoint = searchLocation(keyText);
                    if (searchGeoPoint != null) {
                      searchBarch(keyText);
                    }
                  }
                });
          }
        });

    mapLayer.setOnClickListener(
        new OnClickListener() {

          int i;

          @Override
          public void onClick(View v) {

            i++;
            int value = i % 2;
            switch (value) {
              case 0:
                mapView.setTraffic(false);
                mapView.setSatellite(false);
                break;
              case 1:
                mapView.setTraffic(false);
                mapView.setSatellite(true);

                break;
            }
          }
        });
    showItems.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (enter_distance_layout.getVisibility() == View.VISIBLE) {
              enter_distance_layout.setVisibility(View.GONE);
            } else {

              enter_distance_layout.setVisibility(View.VISIBLE);
            }
          }
        });
    myLocation.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            goToMyLocation();
          }
        });
    handler = new Handler();
    enter_distance_layout = (ViewGroup) findViewById(R.id.enter_distance_layout);
  }
  /**
   * Called when the activity is first created.
   *
   * @see com.google.android.maps.MapActivity#onCreate(android.os.Bundle)
   */
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // start trace
    // Debug.startMethodTracing("x");
    Debug.startMethodTracing("/data/data/com.microjobsinc.mjandroid/x.trace");
    setContentView(R.layout.main);

    db = new MicroJobsDatabase(this);

    // Get current position
    // The LocationManager is a special class that
    // Android instantiates for you, and you can retrieve the
    // instance for your application through the call to
    // getSystemService.
    final Location myLocation =
        getCurrentLocation((LocationManager) getSystemService(Context.LOCATION_SERVICE));

    Spinner spnLocations = (Spinner) findViewById(R.id.spnLocations);

    // Connect the Java MapView to the attributes defined for it in
    // main.xml, and
    mvMap = (MapView) findViewById(R.id.mapmain);
    // Get the map controller
    final MapController mc = mvMap.getController();
    // Create a LocationOverlay that will build and draw the Map in our
    // MapView when we want to view a map of our local area.
    mMyLocationOverlay = new MyLocationOverlay(this, mvMap);
    mMyLocationOverlay.enableMyLocation();
    // The first thing we do with mMyLocationOverlay is define
    // a method that Android will call when we receive our first
    // location fix from the location provider
    mMyLocationOverlay.runOnFirstFix(
        new Runnable() {
          public void run() {
            // move the map to the current location (given by
            // mMyLocationOverlay.getMyLocation()
            mc.animateTo(mMyLocationOverlay.getMyLocation());
            mc.setZoom(16);
          }
        });
    // Identify a marker to use on mMyLocationOverlay to mark
    // available jobs
    Drawable marker = getResources().getDrawable(R.drawable.android_tiny_image);
    marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
    // add the marker overlay to the list of overlays for the MapView mvMap.
    mvMap.getOverlays().add(new MJJobsOverlay(marker));
    // set some initial attributes for mvMap
    // We want users to be able to click(tap) on
    // a job to display more detail about this job
    mvMap.setClickable(true);
    // This method is inherited from android.view.View
    // it enables the standard map functions(zooming, panning)
    mvMap.setEnabled(true);
    // Setting this flag adds a satellite view
    mvMap.setSatellite(false);
    mvMap.setTraffic(false);
    mvMap.setStreetView(false);

    // start out with a general zoom
    mc.setZoom(16);
    mvMap.invalidate();

    // Create a button click listener for the List Jobs button.
    Button btnList = (Button) findViewById(R.id.btnShowList);
    btnList.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            Intent intent = new Intent(MicroJobs.this.getApplication(), MicroJobsList.class);
            startActivity(intent);
          }
        });

    // A list of favorite locations that the Spinner will
    // display and the user can select
    List<String> lsLocations = new ArrayList<String>();
    // Load a HashMap with locations and positions
    final HashMap<String, GeoPoint> hmLocations = new HashMap<String, GeoPoint>();
    hmLocations.put("Current Location", new GeoPoint(latitude, longitude));
    lsLocations.add("Current Location");

    // Add favorite locations from this user's record in workers table
    worker = db.getWorker();
    hmLocations.put(
        worker.getColLoc1Name(),
        new GeoPoint((int) worker.getColLoc1Lat(), (int) worker.getColLoc1Long()));
    lsLocations.add(worker.getColLoc1Name());
    hmLocations.put(
        worker.getColLoc2Name(),
        new GeoPoint((int) worker.getColLoc2Lat(), (int) worker.getColLoc2Long()));
    lsLocations.add(worker.getColLoc2Name());
    hmLocations.put(
        worker.getColLoc3Name(),
        new GeoPoint((int) worker.getColLoc3Lat(), (int) worker.getColLoc3Long()));
    lsLocations.add(worker.getColLoc3Name());
    // Spinner views require an ArrayAdapter to feed them the list,
    // attaching the list of locations to the ArrayAdapter
    ArrayAdapter<String> aspnLocations =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lsLocations);
    // Provide the Spinner with the drop-down layout necessary for the user
    // to display the whole list of locations.
    aspnLocations.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spnLocations.setAdapter(aspnLocations);

    // Setup a callback for the spinner
    spnLocations.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          public void onNothingSelected(AdapterView<?> arg0) {}
          // Enables the appropriate action when the user clicks on an item
          public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
            TextView vt = (TextView) v;
            if ("Current Location".equals(vt.getText())) {
              mMyLocationOverlay.enableMyLocation();
              try {
                mc.animateTo(mMyLocationOverlay.getMyLocation());
              } catch (Exception e) {
                Log.i("MicroJobs", "Unable to animate map", e);
              }
              mvMap.invalidate();
            } else {
              mMyLocationOverlay.disableMyLocation();
              mc.animateTo(hmLocations.get(vt.getText()));
            }
            mvMap.invalidate();
          }
        });
  }