List of usage examples for android.location Location hasBearing
public boolean hasBearing()
From source file:de.ncoder.sensorsystem.android.logging.JSONUtils.java
private static Object wrapLocation(Location loc) { try {/*from w w w . j a v a 2 s. com*/ JSONObject json = new JSONObject(); json.put("provider", loc.getProvider()); json.put("latitude", loc.getLatitude()); json.put("longitude", loc.getLongitude()); if (loc.hasAccuracy()) json.put("accuracy", loc.getAccuracy()); json.put("time", loc.getTime()); if (loc.hasAltitude()) json.put("alt", loc.getAltitude()); if (loc.hasSpeed()) json.put("vel", loc.getSpeed()); if (loc.hasBearing()) json.put("bear", loc.getBearing()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) if (loc.isFromMockProvider()) json.put("mock", true); if (loc.getExtras() != null) { json.put("extra", wrap(loc.getExtras())); } return json; } catch (JSONException e) { return loc.toString() + " threw " + e.toString(); } }
From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java
public static void registerOnThread(Context context, LocationListener locationCallback, Listener listener) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = locationManager.getAllProviders(); Log.i(TAG, "Found " + providers.size() + " location providers"); for (String provider : providers) { if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Provider " + provider + " enabled"); } else {/*from ww w. j a va2 s . co m*/ Log.i(TAG, "Provider " + provider + " disabled"); } } for (int pi = 0; pi < PROVIDERS.length; pi++) { String provider = PROVIDERS[pi]; if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Registering with provider " + provider); Location loc = locationManager.getLastKnownLocation(provider); if (loc != null) { Log.i(TAG, "Last Location, provider=" + loc.getProvider() + ", lat=" + loc.getLatitude() + ", long=" + loc.getLongitude() + ", bearing=" + (loc.hasBearing() ? "" + loc.getBearing() : "NA") + ", speed=" + (loc.hasSpeed() ? "" + loc.getSpeed() : "NA") + ", accuracy=" + (loc.hasAccuracy() ? "" + loc.getAccuracy() : "NA") + ", alt=" + (loc.hasAltitude() ? "" + loc.getAltitude() : "NA")); ZoneService.updateLocation(context, loc); } //if (!"passive".equals(provider)) if (locationCallback != null) locationManager.requestLocationUpdates(provider, 0/*minTime*/, 0/*minDistance*/, locationCallback); } else Log.e(TAG, "Required provider " + provider + " not enabled!"); } if (listener != null) locationManager.addGpsStatusListener(listener); }
From source file:dtu.ds.warnme.app.location.FollowMeLocationSource.java
@Override public void onLocationChanged(Location location) { Log.i(TAG, "Location changed: " + location); if (!location.hasBearing()) { Log.w(TAG, "Location does not have bearing. Will calculate on our own..."); if (previousLocation != null) { float bearing = previousLocation.bearingTo(location); location.setBearing(bearing); Log.w(TAG, "New bearing: " + bearing); }//from www . j a va 2 s . c om previousLocation = location; } if (locationChangedListener != null) { locationChangedListener.onLocationChanged(location); } CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())).zoom(17) .bearing(location.getBearing()).tilt(40).build(); map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); lastKnownLocation = location; pullNewEvents(location); checkEventsProximity(location); }
From source file:org.skt.runtime.original.GeoBroker.java
public JSONObject returnLocationJSON(Location loc) { JSONObject o = new JSONObject(); try {//w w w. j a v a2 s . c o m o.put("latitude", loc.getLatitude()); o.put("longitude", loc.getLongitude()); o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null)); o.put("accuracy", loc.getAccuracy()); o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) : null)); o.put("speed", loc.getSpeed()); o.put("timestamp", loc.getTime()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return o; }
From source file:org.apache.cordova.geolocation.GeoBroker.java
public JSONObject returnLocationJSON(Location loc) { JSONObject o = new JSONObject(); try {//from w w w .j a v a 2 s . c o m o.put("latitude", loc.getLatitude()); o.put("longitude", loc.getLongitude()); o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null)); o.put("accuracy", loc.getAccuracy()); o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) : null)); o.put("velocity", loc.getSpeed()); o.put("timestamp", loc.getTime()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return o; }
From source file:com.keithcassidy.finishline.LineCrossingsFragment.java
private void sendCrossing(Location crossing) { SimpleDateFormat dFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); dFormat.setTimeZone(TimeZone.getDefault()); String boat = ""; if (crossing.hasBearing()) { boat = PreferencesUtils.getBoatName(getActivity()) + " "; }/* w w w .jav a 2s. c om*/ String text = boat + dFormat.format(new Date(crossing.getTime())); Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, text); sendIntent.setType("text/plain"); startActivity(sendIntent); }
From source file:fr.louisbl.cordova.gpslocation.CordovaGPSLocation.java
public JSONObject returnLocationJSON(Location loc) { JSONObject o = new JSONObject(); try {//from w ww . j a v a2s.c o m o.put("latitude", loc.getLatitude()); o.put("longitude", loc.getLongitude()); o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null)); o.put("accuracy", loc.getAccuracy()); o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) : null)); o.put("velocity", loc.getSpeed()); o.put("timestamp", loc.getTime()); } catch (JSONException e) { e.printStackTrace(); } return o; }
From source file:to.sven.androidrccar.common.communication.model.LocationMessage.java
/** * Creates a new {@link LocationMessage} from a {@link Location}. * @param location An {@link Location}/*w w w.j a v a 2s.c o m*/ * @param sendPosition Is it allowed to send the Position? * @param sendSpeed Is it allowed to send the Speed? * @param sendBearing Is it allowed to send the Bearing? */ public LocationMessage(Location location, boolean sendPosition, boolean sendBearing, boolean sendSpeed) { this((sendPosition) ? location.getLatitude() : 0, (sendPosition) ? location.getLongitude() : 0, location.hasAltitude() && sendPosition, (sendPosition) ? location.getAltitude() : 0, location.hasAccuracy() && sendPosition, (sendPosition) ? location.getAccuracy() : 0, location.hasBearing() && sendBearing, (sendBearing) ? location.getBearing() : 0, location.hasSpeed() && sendSpeed, (sendSpeed) ? location.getSpeed() : 0); }
From source file:com.google.android.car.kitchensink.sensor.SensorsTestFragment.java
private String getLocationString(CarSensorEvent event) { String lat = mNaString;// w ww. j av a 2 s . c om String lon = mNaString; String accuracy = mNaString; String alt = mNaString; String speed = mNaString; String bearing = mNaString; if (event != null) { Location location = event.getLocation(null); lat = String.valueOf(location.getLatitude()); lon = String.valueOf(location.getLongitude()); accuracy = location.hasAccuracy() ? String.valueOf(location.getAccuracy()) : accuracy; alt = location.hasAltitude() ? String.valueOf(location.getAltitude()) : alt; speed = location.hasSpeed() ? String.valueOf(location.getSpeed()) : speed; bearing = location.hasBearing() ? String.valueOf(location.getBearing()) : bearing; } return getContext().getString(R.string.sensor_location, getTimestamp(event), lat, lon, accuracy, alt, speed, bearing); }
From source file:com.mjhram.geodata.GpsMainActivity.java
private void addLocationMarker(Location loc) { LatLng driverPosition = new LatLng(loc.getLatitude(), loc.getLongitude()); BitmapDescriptor bmp;/*w ww .j a va2 s . c om*/ float spd = loc.getSpeed(); if (loc.hasBearing()) { if (spd < 1.0) {//3.6km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.arrowup_red); } else if (spd >= 1 && spd < 6) {//21km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.arrowup_orange); } else if (spd >= 6 && spd < 12) {//43km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.arrowup_cyan); } else //if(spd>=12 && spd<20) {//72km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.arrowup_green); } } else { if (spd < 1.0) {//3.6km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.circle_red); } else if (spd >= 1 && spd < 6) {//21km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.circle_orange); } else if (spd >= 6 && spd < 12) {//43km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.circle_cyan); } else //if(spd>=12 && spd<20) {//72km/h bmp = BitmapDescriptorFactory.fromResource(R.drawable.circle_grn); } } MarkerOptions markerOptions = new MarkerOptions().position(driverPosition).icon(bmp).title("").flat(true) //.snippet(driverInfo[i].phone) //.anchor(0.5f, 0.5f) //.draggable(true); .rotation(Math.round(loc.getBearing())); Marker aMarker = googleMap.addMarker(markerOptions); locationMarkers.add(aMarker); }