public void showBudburstSpeciesOnMap(boolean hasHandler) { // TODO Auto-generated method stub otDBH = new OneTimeDBHelper(MapViewMain.this); GeoPoint gPoint = new GeoPoint((int) (mLatitude * 1000000), (int) (mLongitude * 1000000)); mMapView.setBuiltInZoomControls(true); mMapView.invalidate(); if (getMyListsFromDB()) { Log.i("K", "Get species lists from the database"); // add overlays on the map mMapView.getOverlays().clear(); mMapView.getOverlays().add(new SpeciesMapOverlay(mMapView, mMarker, mPlantList)); mMapView.getOverlays().add(mMyOverLay); titleBar.setText("Total number of species : " + mPlantList.size()); mMapController.setCenter(gPoint); if (hasHandler) { mHandlerDone = true; mHandler.sendEmptyMessage(GET_MY_OBSERVED_LISTS); mMapController.setZoom(12); } } else { Toast.makeText(MapViewMain.this, "Please make your own observation", Toast.LENGTH_SHORT) .show(); Log.i("K", "No species lists in the database."); } }
@Override public void onPause() { super.onPause(); if (mMapView != null) { mMapView.invalidate(); mMapView.postInvalidate(); } }
@Override public void onCreate(Bundle savedInstanceState) { Log.i("K", "PBBMapMain - onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.pbb_map); mLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Set MapView and the longPressListener mMapView = (MapCustomView) findViewById(R.id.map); mMapView.setBuiltInZoomControls(true); mMapView.setSatellite(false); // set long press listener longPressListener(); // Set mapController mMapController = mMapView.getController(); mMapController.setZoom(12); // Add mylocation overlay mMyOverLay = new MyLocationOverlay(MapViewMain.this, mMapView); mMyOverLay.enableMyLocation(); mMyOverLay.enableCompass(); // remove view of accuracy bar titleBar = (TextView) findViewById(R.id.myloc_accuracy); titleBar.setVisibility(View.GONE); Intent pIntent = getIntent(); mType = pIntent.getExtras().getInt("type", 100); // initialize plantList mPlantList = new ArrayList<HelperPlantItem>(); // initialize marker mMarker = getResources().getDrawable(R.drawable.marker); mMarker.setBounds(0, 0, mMarker.getIntrinsicWidth(), mMarker.getIntrinsicHeight()); IntentFilter inFilter = new IntentFilter(HelperGpsHandler.GPSHANDLERFILTER); registerReceiver(gpsReceiver, inFilter); Log.i("K", "Receiver Register"); showButtonOnMap(); checkGpsIsOn(); }
// Menu option selection handling public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 2: if (!viewFlag) { mMapView.setSatellite(true); viewFlag = true; } else { mMapView.setSatellite(false); viewFlag = false; } return true; case 3: getNewGPS(); return true; case 4: showCategory(); return true; } return false; }
public void getOtherUsersListsFromServer(int category) { // clear overlays mMapView.getOverlays().clear(); Log.i("K", "MapViewMain(category) : " + category); // call the list of species based on the category. SpeciesOthersFromServer getSpecies = new SpeciesOthersFromServer( MapViewMain.this, mMapView, mMyOverLay, category, mLatitude, mLongitude); getSpecies.execute( getString(R.string.get_onetimeob_others) + "?latitude=" + mLatitude + "&longitude=" + mLongitude); }
// put a button on the map private void showButtonOnMap() { // getting the display size Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); MapView.LayoutParams screenLP; // My Location screenLP = new MapView.LayoutParams( MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT, width - 50, 10, MapView.LayoutParams.TOP_LEFT); Button myLocation = new Button(getApplicationContext()); myLocation.setBackgroundResource(R.drawable.menu_mylocation); mMapView.addView(myLocation, screenLP); myLocation.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub GeoPoint currentPoint = null; if (mLatitude == 0.0) { Toast.makeText( MapViewMain.this, getString(R.string.Alert_gettingGPS), Toast.LENGTH_SHORT) .show(); } else { currentPoint = new GeoPoint((int) (mLatitude * 1000000), (int) (mLongitude * 1000000)); mMapController = mMapView.getController(); mMapController.animateTo(currentPoint); mMapController.setZoom(17); } } }); }
private void longPressListener() { // add long press listener mMapView.setOnLongpressListener( new MapCustomView.OnLongpressListener() { @Override public void onLongpress(final MapView view, final GeoPoint longpressLocation) { // TODO Auto-generated method stub // check if there is GPS data received if (mLatitude == 0.0 || mLongitude == 0.0) { Toast.makeText( MapViewMain.this, getString(R.string.Not_Finish_GPS), Toast.LENGTH_SHORT) .show(); } else { runOnUiThread( new Runnable() { @Override public void run() { // TODO Auto-generated method stub // animateTo the location the user pressed. mMapController.animateTo(longpressLocation); mGeocoder = new Geocoder(MapViewMain.this, Locale.getDefault()); try { mAddr = mGeocoder.getFromLocation( longpressLocation.getLatitudeE6() / 1E6, longpressLocation.getLongitudeE6() / 1E6, 1); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (mAddr == null) { Toast.makeText( MapViewMain.this, "Unable to get the location. Please check network connectivity.", Toast.LENGTH_SHORT) .show(); } else { final Address address = mAddr.get(0); // Insert long press action here. new AlertDialog.Builder(MapViewMain.this) .setTitle(getString(R.string.Mapview_Refresh_Species_Lists_Message)) .setMessage( "[ Your clicked address ]\n\n" + address.getAddressLine(0) + ", " + address.getLocality() + ", " + address.getCountryName()) .setPositiveButton( getString(R.string.Button_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // get latitude and longitude values double newLatitude = longpressLocation.getLatitudeE6() / 1E6; double newLongitude = longpressLocation.getLongitudeE6() / 1E6; // remove all markers first mMapView.getOverlays().clear(); // add a flag marker Drawable dMarker = getResources().getDrawable(R.drawable.marker_flag); dMarker.setBounds( 0, 0, dMarker.getIntrinsicWidth(), dMarker.getIntrinsicHeight()); mMapView .getOverlays() .add(new ItemOverlay(dMarker, longpressLocation)); Display display = getWindowManager().getDefaultDisplay(); // call the data from the server SpeciesOthersFromServer getSpecies = new SpeciesOthersFromServer( MapViewMain.this, mMapView, mMyOverLay, 1, newLatitude, newLongitude); getSpecies.execute( getString(R.string.get_onetimeob_others) + "?latitude=" + newLatitude + "&longitude=" + newLongitude); } }) .setNegativeButton( getString(R.string.Button_no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {} }) .show(); } } }); } } }); }