@Override protected void onResume() { myLocationOverlay.enableMyLocation(); myLocationOverlay.enableCompass(); mapView.invalidate(); super.onResume(); }
public void changeMode(boolean getBike) { this.getBike = getBike; mDbHelper.changeMode(this.getBike); this.populateList(this.view_all); infoLayer.update(); mapView.invalidate(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Displaying Zooming controls MapView mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); MapController mc = mapView.getController(); double lat = Double.parseDouble("10.35410"); // latitude double lon = Double.parseDouble("123.91145"); // longitude GeoPoint geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)); mc.animateTo(geoPoint); mc.setZoom(15); mapView.invalidate(); List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.marker); AddItemizedOverlay itemizedOverlay = new AddItemizedOverlay(drawable, this); OverlayItem overlayitem = new OverlayItem(geoPoint, "Hello", "Talamban Campus"); itemizedOverlay.addOverlay(overlayitem); mapOverlays.add(itemizedOverlay); }
public void onDetermined(ArrayList<GeoPoint> alPoint, ArrayList<Integer> alRadius) { GeoPoint oPoint = null; int oRadius = 0; // remove old radiusoverlays for (int i = 0; i < mapView.getOverlays().size(); i++) { RadiusOverlay mROtemp = new RadiusOverlay(oPoint, oRadius); Overlay Otemp = mapView.getOverlays().get(i); if (Otemp.getClass() == mROtemp.getClass()) { mapView.getOverlays().remove(Otemp); i--; } } // add new route overlays for (int i = 0; i < alPoint.size(); i++) { oPoint = alPoint.get(i); oRadius = alRadius.get(i); mapView.getOverlays().add(new RadiusOverlay(oPoint, oRadius)); } mapView.invalidate(); }
@Override public void run() { // TODO Auto-generated method stub try { btnBackMap = (Button) findViewById(R.id.btnBackMap); btnDirection = (Button) findViewById(R.id.btnDirection); // Get intent and receive data from the parent activity Intent intent = getIntent(); Bundle bundle = intent.getExtras(); respectLocation = (PlaceModel) bundle.getSerializable("currentplace"); curLAT = bundle.getDouble("currentLatitude"); curLNG = bundle.getDouble("currentLongitude"); // Set the coordinate for from-point if (fromLocation == null) { fromLocation = new PlaceModel(); fromLocation.setLat(curLAT); fromLocation.setLng(curLNG); } // zoom to current place zoomToCurrentPlace(); // draw place drawPlace(); // buttonOnClick, button Zoom on map setButtonClick(); map.setBuiltInZoomControls(true); map.invalidate(); } catch (Exception e) { } handler.sendEmptyMessage(0); }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.tabs); // Adding the zoom option mapView = (MapView) findViewById(R.id.MapView); LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom); View zoomView = mapView; zoomLayout.addView( zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"32.2217429", " -110.926479"}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(10); mapView.invalidate(); mapView.setSatellite(false); mapView.setStreetView(false); // bTakePicture = (Button)findViewById(R.id.bTakePicture); // bTakePicture.setOnClickListener(this); }
@Override protected void onPostExecute(MapItemOverlay result) { List<Overlay> mapOverlays = mapView.getOverlays(); mapOverlays.clear(); mapOverlays.add(result); mapView.invalidate(); dialog.dismiss(); }
// This will be called when IO operations are done on the other thread. // This runs on the UI thread, so it is safe to change m_loaded // Also, force a redraw of the map, so we can draw the newly-gotten route public void run() { m_loaded = true; // done loading if (m_mapView != null) { // force redraw and stop caching map view m_mapView.invalidate(); m_mapView = null; } }
@Override public void onStart() { super.onStart(); mapController = mapView.getController(); mapController.setCenter(homeLocation); mapOverlays = mapView.getOverlays(); mapOverlays.add(new MapKeyOverlay(this, null, 0, null)); mapView.invalidate(); }
private void addbanks() { bankOverlay.clearOverlay(); if (branchListModels != null) { for (BranchListModel brankBranchListModel : branchListModels) { addBank(brankBranchListModel); } } mapView.invalidate(); }
public void onLocationChanged(Location location) { myLong = (int) (location.getLongitude() * 1E6); myLat = (int) (location.getLatitude() * 1E6); myLocation = new GeoPoint(myLat, myLong); CustomPinPoint pinPoints = new CustomPinPoint(d, Maps.this); OverlayItem pinPoint = new OverlayItem(myLocation, "Hey guys", "Whatsup"); pinPoints.addPinPoint(pinPoint); overlayList.add(pinPoints); mvMain.invalidate(); }
public void paintTasks() { allOverlays = mapView.getOverlays(); allOverlays.remove(tasksPositionOverlay); tasksPositionOverlay = new TasksOverlay(doneMarker, this); tasksCursor = global_app.getDataStorage().getAllTasks(); DecimalFormat km = new DecimalFormat(); km.setMaximumFractionDigits(2); DecimalFormat m = new DecimalFormat(); m.setMaximumFractionDigits(1); while (tasksCursor.moveToNext()) { double lat = tasksCursor.getDouble(tasksCursor.getColumnIndex(DataStorage.C_LAT)); double lon = tasksCursor.getDouble(tasksCursor.getColumnIndex(DataStorage.C_LON)); String taskTitle = (tasksCursor.getString(tasksCursor.getColumnIndex(DataStorage.C_NAME))); int taskState = (tasksCursor.getInt(tasksCursor.getColumnIndex(DataStorage.C_STATE))); int taskId = (tasksCursor.getInt(tasksCursor.getColumnIndex(DataStorage.C_ID))); GeoPoint taskLocation = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)); Location tmp = new Location(provider); tmp.setLatitude(lat); tmp.setLongitude(lon); double distance = lastLocation.distanceTo(tmp); String prettyDistance; if (distance > 1000) prettyDistance = km.format(distance / 1000) + "km"; else prettyDistance = m.format(distance) + "m"; OverlayItem taskOverlayItem = new OverlayItem( taskLocation, taskTitle + " (id: " + Integer.toString(taskId) + ")", "oddalone o: " + prettyDistance); Drawable marker; switch (taskState) { case 0: marker = cancelMarker; break; case 1: marker = pendingMarker; break; case 2: marker = currentMarker; break; default: marker = doneMarker; break; } int w = marker.getIntrinsicWidth(); int h = marker.getIntrinsicHeight(); marker.setBounds(-w / 2, -h, w / 2, 0); taskOverlayItem.setMarker(marker); tasksPositionOverlay.addOverlay(taskOverlayItem); } allOverlays.add(tasksPositionOverlay); mapView.invalidate(); tasksCursor.close(); }
@Override public boolean onTap(GeoPoint p, MapView mapView) { // All we need to know is where the user tapped. Then we update the // Graticule and let the listener know. if (mHandleTaps) { mGraticule = new Graticule(p); mListener.graticuleUpdated(mGraticule); mapView.invalidate(); return true; } else { return false; } }
public void init() { switch (parent.mapTask) { case 0: navigateToPoint(parent.naviPoint); break; case 1: navigaleToMapItem(parent.mapItemType, parent.mapItemIndex); break; } if (parent.mapTask != -1) { parent.mapTask = -1; } mapView.invalidate(); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final MapView mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); mapView.getZoomButtonsController().setAutoDismissed(false); mapView.displayZoomControls(true); overlay = new SampleBalloonItemizedOverlay(mapView); mapView.getOverlays().add(overlay); mapView.getController().animateTo(new GeoPoint(42431320, -8642187)); mapView.getController().setZoom(16); mapView.invalidate(); }
@Override public boolean onTouchEvent(MotionEvent e, MapView mapView) { if (e.getAction() == MotionEvent.ACTION_DOWN) { switch (mode) { case SEARCH_NEARBY_CURRENT_LOCATION: if (products == null || products.size() == 0) { return false; } GeoPoint touchPoint = mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY()); double minDistance = Double.MAX_VALUE; int index = 0; int touchIndex = 0; for (ProductInfo productInfo : products) { double distance = Math.sqrt( Math.pow(touchPoint.getLatitudeE6() - productInfo.lat * 1E6, 2) + Math.pow(touchPoint.getLongitudeE6() - productInfo.lng * 1E6, 2)); if (distance < minDistance) { minDistance = distance; touchIndex = index; } index++; } Intent intent = new Intent(context, ViewProductActivity.class); intent.putExtra(Global.PRODUCT_INFO, products.get(touchIndex)); context.startActivity(intent); return true; case SEARCH_NEARBY_LOCATION: radius = NO_RADIUS; center = mapView .getProjection() .fromPixels( (int) e.getX() - OVERLAY_WIDTH / 2, (int) e.getY() - OVERLAY_WIDTH / 2); mapView.invalidate(); break; default: break; } } return false; }
@Override public boolean onTap(GeoPoint p, MapView mapView) { /** Track the popup display */ boolean isRemovePriorPopup = mSelectedMapLocation != null; /** Test whether a new popup should display */ mSelectedMapLocation = getHitMapLocation(mapView, p); if (isRemovePriorPopup || mSelectedMapLocation != null) { mapView.invalidate(); } /** Return true if we handled this onTap() */ return mSelectedMapLocation != null; }
public void paintCurrentPostion() { int lat = (int) ((new Double(lastLocation.getLatitude())) * 1E6); int lng = (int) ((new Double(lastLocation.getLongitude())) * 1E6); geoPoint = new GeoPoint(lat, lng); allOverlays = mapView.getOverlays(); allOverlays.remove(updatablePositionOverlay); updatablePositionOverlay = new TasksOverlay(userMarker, this); updatablePositionOverlay.addOverlay( new OverlayItem( geoPoint, global_app.getUsername(), Double.toString(Double.valueOf(lastLocation.getLatitude())) + " " + Double.toString(Double.valueOf(lastLocation.getLongitude())))); allOverlays.add(updatablePositionOverlay); mapView.invalidate(); }
/** * Search the geo-location and zoom the map to that point. * * @param addressEntered The address entered by the user to search. */ private void goToLocation(final String addressEntered) { if (!TextUtils.isEmpty(addressEntered.trim())) { Geocoder geoCode = new Geocoder(this); try { // Get top 5 matched address for this location. final List<Address> foundAdresses = geoCode.getFromLocationName(addressEntered, 5); if (foundAdresses.isEmpty()) { // If no address found, show error through toast. Toast.makeText(this, getResources().getText(R.string.error_message), Toast.LENGTH_LONG) .show(); } else { // Else display address on map and // store results as longitude and latitude. Address address = foundAdresses.get(ZERO_INDEX); Double latitude = address.getLatitude() * 1E6; Double longitude = address.getLongitude() * 1E6; GeoPoint point = new GeoPoint(latitude.intValue(), longitude.intValue()); List<Overlay> mapOverlays = mMapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.marker); MapsMarkerOverlay itemizedoverlay = new MapsMarkerOverlay(drawable, getApplicationContext()); OverlayItem overlayitem = new OverlayItem(point, null, null); itemizedoverlay.addOverlay(overlayitem); if (mapOverlays.size() > 0) { mapOverlays.remove(0); } mapOverlays.add(itemizedoverlay); mMapView.preLoad(); // Show the location in the center of the map. mMapController.setCenter(point); mMapController.animateTo(point); mMapController.setZoom(LOCATION_ZOOM_LEVEL); mMapView.invalidate(); } } catch (IOException e) { e.printStackTrace(); } } }
public void onLocationChanged(Location location) { GeoPoint gpoint = new GeoPoint((int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6)); // Drawable d = context.getResources().getDrawable(R.drawable.ic_launcher); BusFinderActivity.myPoint = gpoint; // map.getOverlays().remove(BusFinderActivity.myPosition); // BusFinderActivity.myPosition = new MyLocOverlay(gpoint, "MyLoc","snipped"); BusFinderActivity.myPosition.clear(); BusFinderActivity.myPosition.insertPinpoint( new PItem(BusFinderActivity.myPoint, "mypoint", "snippet")); // map.getOverlays().add(BusFinderActivity.myPosition); if (isMove()) { map.getController().animateTo(gpoint); } map.invalidate(); Log.d( TAG, "lat=" + gpoint.getLatitudeE6() / 1E6 + ";" + "lon=" + gpoint.getLongitudeE6() / 1E6); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); MapView mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); mc = mapView.getController(); adres2 = getIntent().getExtras().getString("adres"); if (!(adres2.isEmpty())) { p = createGeopoint(adres2); } else { p = createGeopoint("Groningen"); p = null; // plaats geen vlaggetje } // maak een mapoverlay voor point p MapOverlay mapOverlay = new MapOverlay(); List<Overlay> listOfOverlays = mapView.getOverlays(); listOfOverlays.clear(); listOfOverlays.add(mapOverlay); mapView.invalidate(); }
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.maps); mvMain = (MapView) findViewById(R.id.mvMain); mvMain.setBuiltInZoomControls(true); Touchy t = new Touchy(); overlayList = mvMain.getOverlays(); overlayList.add(t); myPin = new MyLocationOverlay(Maps.this, mvMain); overlayList.add(myPin); myController = mvMain.getController(); myController.setZoom(15); GeoPoint myGeoPoint = new GeoPoint(50000, 100000); d = getResources().getDrawable(R.drawable.pin_blue); // placing pinpoint at location Criteria crit = new Criteria(); lm = (LocationManager) getSystemService(LOCATION_SERVICE); towers = lm.getBestProvider(crit, false); Location location = lm.getLastKnownLocation(towers); if (location != null) { myLong = (int) (location.getLongitude() * 1E6); myLat = (int) (location.getLatitude() * 1E6); myLocation = new GeoPoint(myLat, myLong); CustomPinPoint pinPoints = new CustomPinPoint(d, Maps.this); OverlayItem pinPoint = new OverlayItem(myLocation, "Hey guys", "Whatsup"); pinPoints.addPinPoint(pinPoint); overlayList.add(pinPoints); mvMain.invalidate(); myController.animateTo(myLocation); } else { Toast.makeText(getBaseContext(), "Failed to obtain Location", Toast.LENGTH_SHORT); } }
private void setUpView() { String[] listOfCommon = null; String[] listOfDistinct = null; Bundle b = getIntent().getExtras(); // Getting the Bundle object that // pass from another activity // [Single/Multiple, GroupName, UserName] selectedProperty = b.getStringArray("SelectedProperty"); // Log.v(">>> ", Arrays.toString(selectedProperty)); responseString = ss.findUsersLocation(selectedProperty[2], selectedProperty[1]); // if there is only one person in a database if (selectedProperty[0].equals("Single")) { // Latitude, Longitude locationCoord = responseString.split(", "); overlay = new CustomOverlay[2]; // if there are many persons with the same name } else if (selectedProperty[0].equals("Multiple")) { // pairs of latitude and longitude String[] parseString = UtilityClass.parseString(responseString); // String[] parseString = responseString.replace("[", "").replace("]", "") // .split("\\,\\s"); overlay = new CustomOverlay[parseString.length]; // create a list of locations which repeat in a list listOfCommon = findCommon(parseString); // create a list of distinct locations listOfDistinct = findDistinct(parseString); Log.v("List of distinct >>", Arrays.toString(listOfDistinct)); Log.v("List of common >>", Arrays.toString(listOfCommon)); } // Log.v("LOCATION >>> ", responseString); mapView = (MapView) findViewById(R.id.map); mapView.setBuiltInZoomControls(true); Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher); GooglePin itemizedoverlay = new GooglePin(drawable, this); /* TO-DO get details from the hashMap */ // hashMap.get("") List<Overlay> mapOverlays = mapView.getOverlays(); float mRadius = timeMap.get(currentHour); if (selectedProperty[0].equals("Multiple")) { int i = 0; for (int x = 0, y = 1; y < listOfDistinct.length; x += 2, y += 2) { if (listOfDistinct[x] == null) continue; lat = Double.parseDouble(listOfDistinct[x]); lng = Double.parseDouble(listOfDistinct[y]); p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); overlay[i] = new CustomOverlay(p, mRadius); mapView.getOverlays().add(overlay[i++]); mc = mapView.getController(); mc.animateTo(p); } for (int x = 0, y = 1; y < listOfCommon.length; x += 2, y += 2) { if (listOfCommon[x] == null) continue; lat = Double.parseDouble(listOfCommon[x]); lng = Double.parseDouble(listOfCommon[y]); p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); mapView.getController().setCenter(p); OverlayItem overlayitem = new OverlayItem(p, "User", "Location"); itemizedoverlay.addOverlay(overlayitem); mapOverlays.add(itemizedoverlay); mc = mapView.getController(); } mc.setZoom(20); mapView.invalidate(); } else { lat = Double.parseDouble(locationCoord[0]); lng = Double.parseDouble(locationCoord[1]); p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); overlay[0] = new CustomOverlay(p, mRadius); mapView.getOverlays().add(overlay[0]); mc = mapView.getController(); mc.animateTo(p); mapView.invalidate(); } }
@Override protected void onAttachedToWindow() { LogManager.d("onattach"); super.onAttachedToWindow(); Location cache = getCachedLocation(); if (isBetterLocation(cache, mCurrentLocation)) { setCurrentLocation(cache); } // Check status of GPS and NETWORK boolean gpsProviderFlag = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean networkProviderFlag = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if ((!gpsProviderFlag || !networkProviderFlag) && mFirstShow) { Log.d("Location", "No location provider is enabled"); mFirstShow = false; buildAlertMessageNoLocationService(); } else { if (gpsProviderFlag) { locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 10000, 0, mLocationListener1); } if (networkProviderFlag) { locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 10000, 0, mLocationListener2); } addCurrentLocationOverlay(); // (int)(37 * 1000000), (int)(111.37 * 1000000) // for direction test // addBank(geoBeijing); mMapShowingForLocationUpdate = true; mapView.invalidate(); Handler handler = new Handler(); Runnable myRunnable = new Runnable() { public void run() { locationManager.removeUpdates(mLocationListener1); locationManager.removeUpdates(mLocationListener2); } }; handler.postDelayed(myRunnable, 300000); httpSearchHandler = new Handler() { @Override public void handleMessage(Message msg) { if (HttpConnectionUtil.SUCCESS == msg.what) { String response = (String) msg.getData().get("response"); Log.d("map", "response : " + response); GeocodeResult geocodeResult = new GeocodeResult(); geocodeResult.setValues(response); mapCon.setZoom(defaultZoom); mapCon.setCenter(geocodeResult.getGeoPoint()); } else { Toast.makeText(getContext(), "error", Toast.LENGTH_LONG).show(); } } }; } goToMyLocation(); }
/** * 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(); } }); }
public static void clearOverlays(MapView mapView) { if (!mapView.getOverlays().isEmpty()) { mapView.getOverlays().clear(); mapView.invalidate(); } }
/** Called when the activity is first created. */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Displaying Zooming controls final MapView mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); /** Changing Map Type */ // mapView.setSatellite(true); // Satellite View // mapView.setStreetView(true); // Street View // mapView.setTraffic(true); // Traffic view mapOverlays = mapView.getOverlays(); drawable = this.getResources().getDrawable(R.drawable.mark_red); itemizedOverlay = new AddItemizedOverlay(drawable, this); final DrivingDirectionsGoogleKML googleKML = new DrivingDirectionsGoogleKML(); final GeoPoint startPoint = new GeoPoint((int) (-29.7639 * 1E6), (int) (-51.1446 * 1E6)); final GeoPoint endPoint = new GeoPoint((int) (-29.7700 * 1E6), (int) (-51.1407 * 1E6)); // -29.7700, -51.1407 /** Placing Start and End Marker */ itemizedOverlay.addOverlay(new OverlayItem(startPoint, "Start point", "router")); mapOverlays.add(itemizedOverlay); itemizedOverlay.addOverlay(new OverlayItem(endPoint, "End point", "router")); mapOverlays.add(itemizedOverlay); /** showing location by Latitude and Longitude */ final MapController mc = mapView.getController(); mc.animateTo(startPoint); mc.setZoom(15); mapView.invalidate(); googleKML.driveTo( startPoint, endPoint, Mode.DRIVING, new IDirectionsListener() { @Override public void onDirectionsNotAvailable() { System.out.println("DirectionsNotAvailable"); } @Override public void onDirectionsAvailable(final Route route, final Mode mode) { System.err.println(route.getTotalDistance()); System.out.println(">> GEOPOINTS <<"); final List<GeoPoint> geopoints = route.getGeoPoints(); for (final GeoPoint geoPoint : geopoints) { System.out.println( "lat.: " + geoPoint.getLatitudeE6() + " long.: " + geoPoint.getLongitudeE6()); } /** Placing Route */ drawPath(geopoints, Color.BLUE); System.out.println(">> Placemark <<"); final List<Placemark> placemarks = route.getPlacemarks(); for (final Placemark placemark : placemarks) { /** Placing Marker */ // final GeoPoint location = placemark.getLocation(); // if (location != null) { // final OverlayItem overlayitem = new OverlayItem(location, // placemark.getDistance(), placemark.getInstructions()); // itemizedOverlay.addOverlay(overlayitem); // mapOverlays.add(itemizedOverlay); // } System.out.println( "dintance: " + placemark.getDistance() + " instructions: " + placemark.getInstructions()); } } }); }
@Override protected void onPause() { super.onPause(); mapView.invalidate(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_code); MapView mapView = (MapView) findViewById(R.id.mapView); LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom); @SuppressWarnings("deprecation") View zoomView = mapView.getZoomControls(); zoomLayout.addView( zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"26.0607739", "50.5553531"}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(12); mapView.invalidate(); List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.bin); MapItemizedOverly itemizedoverlay = new MapItemizedOverly(drawable, this); int lat2 = 26127948; int lng4 = 50588877; p = new GeoPoint((int) (lat2 / 1E6), (int) (lng4 / 1E6)); GeoPoint JwdCentre = new GeoPoint(lat2, lng4); OverlayItem overlayItemJwdCentre = new OverlayItem( JwdCentre, "Jawad , The Centre", "Available Types: Plastic,Paper,Metal,Glass"); int lat1 = 26164950; int lng1 = 50544669; z = new GeoPoint((int) (lat1 / 1E6), (int) (lng1 / 1E6)); GeoPoint BP = new GeoPoint(lat1, lng1); OverlayItem overlayItemBP = new OverlayItem(BP, "Bahrain Polytechnic", "Available Types: Plastic,Paper,Metal"); int lat0 = 26277675; int lng0 = 50662026; t = new GeoPoint((int) (lat0 / 1E6), (int) (lng0 / 1E6)); GeoPoint OsraAmwj = new GeoPoint(lat0, lng0); OverlayItem overlayitemOsraAmwj = new OverlayItem( OsraAmwj, "Al Osra Market ,Amwaj", "Available Types: Plastic,Paper,Metal,Glass"); int lat3 = 26216668; int lng3 = 50479486; Njb = new GeoPoint((int) (lat3 / 1E6), (int) (lng3 / 1E6)); GeoPoint Najibi = new GeoPoint(lat3, lng3); OverlayItem overlayitemNajinbi = new OverlayItem(Najibi, "Najibi Mall", "Available Types: Plastic,Paper,Metal,Glass"); int lat5 = 26221076; int lng5 = 50489421; Fd = new GeoPoint((int) (lat5 / 1E6), (int) (lng5 / 1E6)); GeoPoint FdG = new GeoPoint(lat5, lng5); OverlayItem overlayitemFdG = new OverlayItem(FdG, "Jawad Food Garden", "Available Types: Plastic,Paper,Metal,Glass"); int lat6 = 26221076; int lng6 = 50489421; Mi = new GeoPoint((int) (lat6 / 1E6), (int) (lng6 / 1E6)); GeoPoint MidH = new GeoPoint(lat6, lng6); OverlayItem overlayitemMid = new OverlayItem( MidH, "Midway Market , Hamalah", "Available Types: Plastic,Paper,Metal,Glass"); int lat7 = 26229356; int lng7 = 50542167; BEC = new GeoPoint((int) (lat7 / 1E6), (int) (lng7 / 1E6)); GeoPoint BECI = new GeoPoint(lat7, lng7); OverlayItem overlayitemBEC = new OverlayItem(BECI, "Bahrain Exhibition Centre", "Available Types: Aluminum,Paper,Glass"); int lat8 = 26195681; int lng8 = 50478112; SarC = new GeoPoint((int) (lat8 / 1E6), (int) (lng8 / 1E6)); GeoPoint SC = new GeoPoint(lat8, lng8); OverlayItem overlayitemSC = new OverlayItem(SC, "Sar Cinema", "Available Types: Aluminum,Paper,Glass,Plastic"); int lat9 = 26130232; int lng9 = 50656794; DarI = new GeoPoint((int) (lat9 / 1E6), (int) (lng9 / 1E6)); GeoPoint Dar = new GeoPoint(lat9, lng9); OverlayItem overlayitemDar = new OverlayItem(Dar, "Al Dar Island", "Available Types: Aluminum,Paper,Glass,Plastic"); int lat10 = 26229150; int lng10 = 50537321; GeantG = new GeoPoint((int) (lat10 / 1E6), (int) (lng10 / 1E6)); GeoPoint Geant = new GeoPoint(lat10, lng10); OverlayItem overlayitemGeant = new OverlayItem(Geant, "Geant", "Available Types: Plastic Bags"); int lat11 = 26097468; int lng11 = 50564435; Rv = new GeoPoint((int) (lat11 / 1E6), (int) (lng11 / 1E6)); GeoPoint RiffaViews = new GeoPoint(lat11, lng11); OverlayItem overlayitemRv = new OverlayItem(RiffaViews, "Riffa Views", "Available Types: Aluminum,Paper,Glass,Plastic"); int lat12 = 26205629; int lng12 = 50499065; Stc = new GeoPoint((int) (lat12 / 1E6), (int) (lng12 / 1E6)); GeoPoint StChris = new GeoPoint(lat12, lng12); OverlayItem overlayitemStc = new OverlayItem( StChris, "St. Christophers Junior School", "Available Types: Aluminum,Paper,Glass,Plastic"); int lat13 = 26212435; int lng13 = 50592926; NY = new GeoPoint((int) (lat13 / 1E6), (int) (lng13 / 1E6)); GeoPoint NYIT = new GeoPoint(lat13, lng13); OverlayItem overlayitemNY = new OverlayItem( NYIT, "New York Institute Of Technology", "Available Types: Aluminum,Paper,Glass,Plastic"); int lat14 = 26179689; int lng14 = 50536672; AK = new GeoPoint((int) (lat14 / 1E6), (int) (lng14 / 1E6)); GeoPoint Kano = new GeoPoint(lat14, lng14); OverlayItem overlayitemKano = new OverlayItem( Kano, "Abdulrahman Kanoo School", "Available Types: Aluminum,Paper,Glass,Plastic"); itemizedoverlay.addOverlay(overlayitemKano); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemNY); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemStc); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemRv); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemGeant); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemDar); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemSC); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayItemJwdCentre); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayItemBP); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemOsraAmwj); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemNajinbi); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemFdG); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemMid); mapOverlays.add(itemizedoverlay); itemizedoverlay.addOverlay(overlayitemBEC); mapOverlays.add(itemizedoverlay); MapController mapController = mapView.getController(); mapController.animateTo(BP); mapController.setZoom(12); mapController.animateTo(OsraAmwj); mapController.setZoom(12); mapController.animateTo(JwdCentre); mapController.setZoom(12); mapController.animateTo(Najibi); mapController.setZoom(12); mapController.animateTo(FdG); mapController.setZoom(12); mapController.animateTo(MidH); mapController.setZoom(12); mapController.animateTo(BECI); mapController.setZoom(12); mapController.animateTo(SC); mapController.setZoom(12); mapController.animateTo(Dar); mapController.setZoom(12); mapController.animateTo(Geant); mapController.setZoom(12); mapController.animateTo(RiffaViews); mapController.setZoom(12); mapController.animateTo(StChris); mapController.setZoom(12); mapController.animateTo(NYIT); mapController.setZoom(12); mapController.animateTo(Kano); mapController.setZoom(12); }
private void DrawTransports(String jsonString, Boolean isCenter) { List<Overlay> mapOverlays = null; MapView mapView = (MapView) findViewById(R.id.mapview); JSONArray array = String2JsonArray(jsonString); if (array != null) { int minLatitude = Integer.MAX_VALUE, minLongitude = Integer.MAX_VALUE; int maxLatitude = Integer.MIN_VALUE, maxLongitude = Integer.MIN_VALUE; EditText et = (EditText) findViewById(R.id.editTextInfo); // TODO: Add show marshruts // et.setText(GetCurrentTime()+". "+String.valueOf(spyMarshrut)+"("+array.length()+")"); Map<String, Integer> infoMap = new HashMap<String, Integer>(); for (int n = 0; n < array.length(); n++) { try { JSONObject jo = array.getJSONObject(n); String info = jo.getString("info"); String marshrutNumber = getTransportNumber(info); if (infoMap.containsKey(marshrutNumber)) { int oldValue = infoMap.get(marshrutNumber); oldValue++; infoMap.put(marshrutNumber, oldValue); } else { infoMap.put(marshrutNumber, 1); } JSONArray coordinatesJsonArray = jo.getJSONArray("cordinate"); int iLatitude, iLongitude; if (coordinatesJsonArray.length() > 1) { iLatitude = (int) (coordinatesJsonArray.getDouble(0) * 1000000); minLatitude = Math.min(minLatitude, iLatitude); maxLatitude = Math.max(minLatitude, iLatitude); iLongitude = (int) (coordinatesJsonArray.getDouble(1) * 1000000); minLongitude = Math.min(minLongitude, iLongitude); maxLongitude = Math.max(minLongitude, iLongitude); String transportNumber = getTransportNumber(info); Drawable drawable; drawable = new TextDrawable(transportNumber); DrawableItemizedOverlay itemizedoverlay = new DrawableItemizedOverlay(drawable, this); GeoPoint point = new GeoPoint(iLatitude, iLongitude); OverlayItem overlayitem = new OverlayItem(point, "Info", info); itemizedoverlay.addOverlay(overlayitem); if (mapOverlays == null) { mapOverlays = mapView.getOverlays(); mapOverlays.clear(); } mapOverlays.add(itemizedoverlay); } } catch (JSONException e) { e.printStackTrace(); } } String s = infoMap.toString(); et.setText(GetCurrentTime() + ". " + s); if (isCenter && minLatitude != Integer.MAX_VALUE) { MapController mapController = mapView.getController(); GeoPoint point = new GeoPoint((minLatitude + maxLatitude) / 2, (minLongitude + maxLongitude) / 2); mapController.animateTo(point); } mapView.invalidate(); } }