private void addbanks() { bankOverlay.clearOverlay(); if (branchListModels != null) { for (BranchListModel brankBranchListModel : branchListModels) { addBank(brankBranchListModel); } } mapView.invalidate(); }
private void addBank(BranchListModel brankBranchListModel) { int la = (int) (brankBranchListModel.getLatitude() * 1e6); int lo = (int) (brankBranchListModel.getLongitude() * 1e6); GeoPoint geoPoint = new GeoPoint(la, lo); BankOverlayItem locaItem = new BankOverlayItem(geoPoint, "CURRENTLOCATION", "CurrentLocation"); locaItem.setBrankBranchListModel(brankBranchListModel); bankOverlay.addOverlay(locaItem); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.googlemaps); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); MapController mapController = mapView.getController(); GeoPoint point = new GeoPoint(42295938, -71297368); mapController.setCenter(point); mapController.setZoom(15); List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.maparrow); MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable, this); OverlayItem overlayitem = new OverlayItem(point, "Wellesley Books!", "82 Central St.\nWellesley, MA 02482"); itemizedoverlay.addOverlay(overlayitem); mapOverlays.add(itemizedoverlay); }
public void addCurrentLocationOverlay() { // GeoPoint point = null; if (overlays.contains(mCurrentLocationOverlay)) { overlays.remove(mCurrentLocationOverlay); } if (mCurrentLocation == null) { mCurrentLocationPoint = mDefaultCurrentLocation; System.out.println("null"); } else { mCurrentLocationPoint = new GeoPoint( (int) (mCurrentLocation.getLatitude() * 1e6), (int) (mCurrentLocation.getLongitude() * 1e6)); System.out.println("add current"); } mCurrentOverlayItem = new OverlayItem(mCurrentLocationPoint, "CURRENTLOCATION", "CurrentLocation"); mCurrentLocationOverlay.clearOverlay(); mCurrentLocationOverlay.addOverlay(mCurrentOverlayItem); overlays.add(mCurrentLocationOverlay); mapView.postInvalidate(); }
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); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); Drawable drawable = this.getResources().getDrawable(R.drawable.map_pin_24); final MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable); mapView = (MapView) findViewById(R.id.mapviewMain); mapView.setBuiltInZoomControls(true); mController = mapView.getController(); mapOverlays = mapView.getOverlays(); myLocationOverlay = new MyLocationOverlay(this, mapView); mapView.getOverlays().add(myLocationOverlay); visitedPoints.clear(); /* * not sure if final should be there but it's required by another method */ final ArrayList<ParcelableGeoPoint> arrayOfParcebleGeoPoints = getIntent().getParcelableArrayListExtra("geoPoints"); Bundle extras = getIntent().getExtras(); mainPoint = extras.getParcelable("mainPoint"); for (ParcelableGeoPoint p : arrayOfParcebleGeoPoints) { points.add(p.getGeoPoint()); notYetReachedPoints.add(p.getGeoPoint()); } int numOfPoints = points.size(); for (int i = 0; i < numOfPoints; i++) { GeoPoint point = points.get(i); OverlayItem overlayitem = new OverlayItem(point, null, null); itemizedoverlay.addOverlay(overlayitem); } ; mapOverlays.add(itemizedoverlay); mapView.postInvalidate(); final Chronometer cm = (Chronometer) findViewById(R.id.chronometer); cm.setBase(SystemClock.elapsedRealtime()); cm.start(); icon = this.getResources().getDrawable(R.drawable.map_pin_24_green); icon.setBounds( 0 - icon.getIntrinsicWidth() / 2, 0 - icon.getIntrinsicHeight(), icon.getIntrinsicWidth() / 2, 0); /*Button checkPoint = (Button) findViewById(R.id.checkpoint); checkPoint.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub } });*/ /* Button summary = (Button) findViewById(R.id.summary); summary.setOnClickListener(new OnClickListener() { public void onClick(View v) { SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putInt("time", time); editor.putInt("averageSpeed", averageSpeed); // TODO Auto-generated method stub Intent myIntent = new Intent(v.getContext(), SummaryActivity.class); myIntent.putExtra("time", cm.getBase()); myIntent.putExtra("geoPoints", arrayOfParcebleGeoPoints); myIntent.putExtra("visitedPoints", visitedPoints); myIntent.putExtra("mainPoint",mainPoint); v.getContext().startActivity(myIntent); finish(); } });*/ lManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onLocationChanged(Location location) { // TODO Auto-generated method stub double lat = location.getLatitude(); double lon = location.getLongitude(); GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lon * 1e6)); visitedPoints.add(new ParcelableGeoPoint(point)); if (prevPoint != null) { mapOverlays.add(new RouteOverlay(prevPoint, point, 0xFF0000)); } if (totalDistance == -1) { totalDistance = 0; } else { totalDistance = totalDistance + location.distanceTo(prevLocation); } prevLocation = location; prevPoint = point; mController.animateTo(point); /* * This for-loop checks at every GPS update if any flag is * within reach. */ for (int i = 0; i < notYetReachedPoints.size(); i++) { destLocation.reset(); destLocation.setLatitude((float) (notYetReachedPoints.get(i).getLatitudeE6() / 1E6)); destLocation.setLongitude( (float) (notYetReachedPoints.get(i).getLongitudeE6() / 1E6)); distance = location.distanceTo(destLocation); if (distanceToNearestPoint > distance) { distanceToNearestPoint = distance; } /* * user catches a flag if current position is within 50m of * a flag */ if (distance < 10) { /* * checkpoint reached */ Context context = getApplicationContext(); CharSequence text = "Checkpoint reached!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); /* * remove the reached point from the list */ for (int a = 0; a < itemizedoverlay.size(); a++) { if (notYetReachedPoints.get(i).equals(itemizedoverlay.getItem(a).getPoint())) itemizedoverlay.getItem(a).setMarker(icon); } notYetReachedPoints.remove(i); /* * change color of flag (code not complete) */ } } /* * not really tested yet */ TextView distance_to_point = (TextView) findViewById(R.id.distance_to_point); distance_to_point.setText("Distance to nearest point: " + distanceToNearestPoint + "m"); speed = location.getSpeed(); TextView speed_text = (TextView) findViewById(R.id.speed); speed_text.setText("Speed: " + speed + "m/s"); TextView totalDistance_text = (TextView) findViewById(R.id.total_distance); totalDistance_text.setText("Total distance: " + totalDistance); if (notYetReachedPoints.isEmpty()) { /* * This is part of a strange bug-fix the location listener * does not shut off when the "finish()" method is called */ lManager.removeUpdates(locationListener); lManager = null; Intent myIntent = new Intent(MainActivity.this, SummaryActivity.class); myIntent.putExtra("time", cm.getBase()); myIntent.putExtra("totalDistance", totalDistance); myIntent.putExtra("geoPoints", arrayOfParcebleGeoPoints); myIntent.putExtra("visitedPoints", visitedPoints); myIntent.putExtra("mainPoint", mainPoint); MainActivity.this.startActivity(myIntent); finish(); } } }; lManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this.locationListener); }