double speed = location.getSpeed(); //spedd in meter/minute speed = (speed*3600)/1000; // speed in km/minute Toast.makeText(GraphViews.this, "Current speed:" + location.getSpeed(),Toast.LENGTH_SHORT).show();
public void onLocationChanged(Location location) { // TODO Auto-generated method stub new_latitude=location.getLatitude(); new_longitude=location.getLongitude(); float speed = location.getSpeed(); //You could also use location.hasSpeed(), which is a boolean, but it almost //always returns True if(speed > DESIRED_LIMIT && previousSpeed > DESIRED_LIMIT){ lat1=new_latitude; lon1=new_longitude; } previousSpeed = speed; }
class GpsListener implements LocationListener{ public void onLocationChanged(Location location) { // TODO Auto-generated method stub double latitude = location.getLatitude(); double longitude = location.getLongitude(); float speed = location.getSpeed(); ... } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }
@Override public void onGPSUpdate(Location location) { location.getLatitude(); location.getLongitude(); speed = location.getSpeed(); double speedKPH = convertSpeed(speed); if(speedKPH > 20.0) { //Do something, Speed Over 20 }else if(speedKPH == 0) { //Do something else, speed 0 } String speedString = "" + roundDecimal(convertSpeed(speed),2); String unitString = measurementUnitString(measurement_index); setSpeedText(R.id.info_message,speedString + " " + unitString); }
container.put("altitude", ""+gpsLocation.getAltitude()); container.put("provider", ""+gpsLocation.getProvider()); container.put("speed", ""+gpsLocation.getSpeed()); map.put("container", (new JSONObject(container)).toString());
values.put(COLUMN_LONGITUDE, location.getLongitude()); values.put(COLUMN_TIME, location.getTime()); values.put(COLUMN_SPEED, location.getSpeed()); values.put(COLUMN_DISTANCE_TO_LAST_LOC, location.distanceTo(lastLocation)); statusTextView.setText("provider " + location.getProvider() + location.getLatitude() + " " + location.getLongitude() + "speed:" + location.getSpeed() + "distance: " + location.distanceTo(lastLocation));
mCurrentSpeed.setText(loc.getSpeed());
mCurrentSpeed.setText(loc.getSpeed());
mCurrentSpeed.setText(loc.getSpeed());
mCurrentSpeed.setText(loc.getSpeed());
// Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { location.getLatitude(); Toast.makeText(context, "Current speed:" + location.getSpeed(), Toast.LENGTH_SHORT).show(); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); }
Log.w("ACCURACY", String.valueOf(loc.getAccuracy() + " m")); Log.w("PROVIDER", String.valueOf(loc.getProvider())); Log.w("SPEED", String.valueOf(loc.getSpeed() + " m/s")); Log.w("ALTITUDE", String.valueOf(loc.getAltitude())); Log.w("BEARING", String.valueOf(loc.getBearing() + " degrees east of true north"));
new LocationListener() { private Location mLastLocation; @Override public void onLocationChanged(Location pCurrentLocation) { //calcul manually speed double speed = 0; if (this.mLastLocation != null) speed = Math.sqrt( Math.pow(pCurrentLocation.getLongitude() - mLastLocation.getLongitude(), 2) + Math.pow(pCurrentLocation.getLatitude() - mLastLocation.getLatitude(), 2) ) / (pCurrentLocation.getTime() - this.mLastLocation.getTime()); //if there is speed from location if (pCurrentLocation.hasSpeed()) //get location speed speed = pCurrentLocation.getSpeed(); this.mLastLocation = pCurrentLocation; //////////// //DO WHAT YOU WANT WITH speed VARIABLE //////////// } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } };
double lng = location.getLongitude(); double bearing = location.getBearing(); double speed = location.getSpeed(); if (lat != 0.0 && lng != 0.0) {
lon = location.getLongitude(); alt = location.getAltitude(); speed = location.getSpeed();
lon = location.getLongitude(); alt = location.getAltitude(); speed = location.getSpeed();
Toast.makeText(neu, "Current speed:" + location.getSpeed(), Toast.LENGTH_SHORT).show();
public void onLocationChanged(Location location) { // Getting latitude of the current location double latitude = location.getLatitude(); // Getting longitude of the current location double longitude = location.getLongitude(); float speed = location.getSpeed(); // Creating a LatLng object for the current location LatLng latLng = new LatLng(latitude, longitude); // Showing the current location in Google Map CameraPosition camPos = new CameraPosition.Builder() .target(new LatLng(latitude, longitude)) .zoom(18) .bearing(location.getBearing()) .tilt(70) .build(); CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(camPos); googleMap.animateCamera(camUpd3); }
private Location oldLocation; private float[] results; private ArrayList<float> speedList; //in oncreate: speedList = new ArrayList<Float>(); private void updateWithNewLocation(Location location) { String where = ""; results = new float[100]; //[100] means there can be 100 entries - decrease or increase the number depending on your output if (location != null) { double lng = location.getLongitude(); double lat = location.getLatitude(); float speed = location.getSpeed(); long time = location.getTime(); String timeString = getTimeString(time); speedList.add(speed); if(oldLocation != null){ Location.distanceBetween(oldLocation.getLatitude(), oldLocation.getLongitude(), lat, lng, results); } oldLocation = location;
Toast.makeText(MapsActivity.this,"Location :"+location.describeContents()+location.getSpeed()+"\n"+location.getAltitude()+"\n"+location.getLatitude()+"\n"+location.getLongitude()+"\n"+location.getProvider()+"\n"+location.getAccuracy(), Toast.LENGTH_SHORT).show();