Android Open Source - GPA Add Location Map Activity






From Project

Back to project page GPA.

License

The source code is released under:

Apache License

If you think the Android project GPA listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bishal.android.taskmanager;
/*from   w w w .  ja  va 2 s .  com*/
import java.io.IOException;
import java.util.List;

import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.maps.GeoPoint;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.bishal.android.taskmanager.views.AddressOverlay;

public class AddLocationMapActivity extends MapActivity {
  
  public static final String ADDRESS_RESULT = "address";
  
  private Button mapLocationButton;
  private Button useLocationButton;
  private EditText addressText;
  private MapView mapView;
  private Address address;
  private MyLocationOverlay myLocationOverlay;
  
  public /*static*/ GeoPoint gp;

  @Override
  protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.add_location);
    setUpViews();
  }

  @Override
  protected void onResume() {
    super.onResume();
    myLocationOverlay.enableMyLocation();
  }
  
  @Override
  protected void onPause() {
    super.onPause();
    myLocationOverlay.disableMyLocation();
  }

  protected void mapCurrentAddress() {
    String addressString = addressText.getText().toString();
    Geocoder g = new Geocoder(this);
    List<Address> addresses;
    try {
      addresses = g.getFromLocationName(addressString, 1);
      if (addresses.size() > 0) {
        address = addresses.get(0);
        List<Overlay> mapOverlays = mapView.getOverlays();
        AddressOverlay addressOverlay = new AddressOverlay(address);
        mapOverlays.add(myLocationOverlay);
        mapOverlays.add(addressOverlay);
        mapView.invalidate();
        final MapController mapController = mapView.getController();
        gp=addressOverlay.getGeopoint();
        mapController.animateTo(gp, new Runnable() {
          public void run() {
            mapController.setZoom(12);
          }
        });
        useLocationButton.setEnabled(true);
      } else {
        // show the user a note that we failed to get an address
      }
    } catch (IOException e) {
      // show the user a note that we failed to get an address
      e.printStackTrace();
    }
  }

  private void setUpViews() {
    addressText = (EditText)findViewById(R.id.task_address);
    mapLocationButton = (Button)findViewById(R.id.map_location_button);
    useLocationButton = (Button)findViewById(R.id.use_this_location_button);
    useLocationButton.setEnabled(false);
    mapView = (MapView)findViewById(R.id.map);
    mapView.setBuiltInZoomControls(true);
    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);
    mapView.invalidate();
    
    useLocationButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        if (null != address) {
          Intent intent = new Intent();
          intent.putExtra(ADDRESS_RESULT, address);
          setResult(RESULT_OK, intent);
        }
        
        finish();
      }
    });
    mapLocationButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        mapCurrentAddress();
      }
    });
  }
  
  @Override
  protected boolean isLocationDisplayed() {
    return true;
  }

  @Override
  protected boolean isRouteDisplayed() {
    return false;
  }

}




Java Source Code List

com.bishal.android.taskmanager.ACCOUNT_INFO.java
com.bishal.android.taskmanager.ADD_TASK.java
com.bishal.android.taskmanager.AddLocationMapActivity.java
com.bishal.android.taskmanager.AddTaskActivity.java
com.bishal.android.taskmanager.AlarmActivity.java
com.bishal.android.taskmanager.AlertDialogManager.java
com.bishal.android.taskmanager.AndroidAlarmService.java
com.bishal.android.taskmanager.CURRENT_LOCATION.java
com.bishal.android.taskmanager.DB_ADAPTER.java
com.bishal.android.taskmanager.DbHelper.java
com.bishal.android.taskmanager.GPA_HOME.java
com.bishal.android.taskmanager.GPS_FIELD.java
com.bishal.android.taskmanager.GPS_INFO.java
com.bishal.android.taskmanager.LOGIN.java
com.bishal.android.taskmanager.MyAlarmService.java
com.bishal.android.taskmanager.SCHEDULES.java
com.bishal.android.taskmanager.SEARCHING_PLACES.java
com.bishal.android.taskmanager.SIGNUP.java
com.bishal.android.taskmanager.Search_Education.java
com.bishal.android.taskmanager.Search_Hospital.java
com.bishal.android.taskmanager.SpecifyTime.java
com.bishal.android.taskmanager.TaskManagerActivity.java
com.bishal.android.taskmanager.TaskManagerApplication.java
com.bishal.android.taskmanager.ViewTasksActivity.java
com.bishal.android.taskmanager.YourAlarmService.java
com.bishal.android.taskmanager.adapters.TaskListAdapter.java
com.bishal.android.taskmanager.tasks.Task.java
com.bishal.android.taskmanager.tasks.TasksSQLiteOpenHelper.java
com.bishal.android.taskmanager.views.AddressOverlay.java
com.bishal.android.taskmanager.views.TaskListItem.java