@Override public void onProgressChanged(SeekBar seekBar, int value, boolean byUser) { Location you = new Location("you"); tvDist.setText("RADIUS: " + ((double) value) / 10 + "km"); if (seekBar == sbRadOuter && byUser) { you.setLatitude(myLatLng.latitude); you.setLongitude(myLatLng.longitude); if (value != 0) { Polyline temp = drawCircle(myLatLng, ((double) value) / 10, Color.BLUE, 5); outerCircle.remove(); outerCircle = temp; for (Marker marker : markersOnMap) { markerLatLng = marker.getPosition(); markerLocation.setLatitude(markerLatLng.latitude); markerLocation.setLongitude(markerLatLng.longitude); if (you.distanceTo(markerLocation) > value * 100) { marker.setVisible(false); } else { marker.setVisible(true); } } } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_testes); dao = new AmbienteDao(this); dao.open(); Location loc = new Location(""); loc.setLatitude(12.345555); loc.setLatitude(6.222555); Ambiente ambiente = new Ambiente(); ambiente.setNome("Dan"); ambiente.setRaio(13.657); ambiente.setLocation(loc); ambiente.setDescricao("nfsçkdljf~ks"); ambiente.setPerfil(Ambiente.SILENCIOSO); ambiente.setData_persist(new Date()); // dao.create(ambiente); // // List<Ambiente> ambs = dao.getAll(); // // for(int i = 0;i<ambs.size();i++){ // Log.d("Ambiente", ambs.get(i).toString()); // System.out.println(ambs.get(i)); // } Log.d("Ambiente", "Ambiente pelo id: " + dao.buscarAmbiente(2).toString()); dao.close(); }
public static ArrayList<ARGeoNode> cleanNoLocation( Activity activity, ARLayerManager layers, ArrayList<GeoNode> list, float[] location, float distanceFilter) { ArrayList<ARGeoNode> cleaned_list = new ArrayList<ARGeoNode>(); Location mLocation = new Location(""); mLocation.setLatitude(location[0]); mLocation.setLongitude(location[1]); Location resLocation = new Location(""); for (int i = list.size() - 1; i >= 0; i--) { GeoNode resource = list.get(i); if (resource == null) { Log.e("ARUtils", "Vacio"); continue; } if ((resource.getLatitude() != -1.0) && (resource.getLongitude() != -1.0)) { if (distanceFilter > 0) { resLocation.setLatitude(resource.getLatitude()); resLocation.setLongitude(resource.getLongitude()); resLocation.setAltitude(mLocation.getAltitude()); if (mLocation.distanceTo(resLocation) > distanceFilter) continue; } ARGeoNode node = new ARGeoNode((ARBase) activity, resource, layers.getInfoLayer()); cleaned_list.add(node); } } return cleaned_list; }
public PlaceDownloaderTask(PlaceViewActivity parent, boolean hasNetwork) { super(); System.out.println("#### at Start PlaceDownloaderTask ctor"); mParent = new WeakReference<PlaceViewActivity>(parent); mHasNetwork = hasNetwork; if (null != parent) { sStubBitmap = BitmapFactory.decodeResource(parent.getResources(), R.drawable.stub); sMockLoc1.setLatitude(37.422); sMockLoc1.setLongitude(-122.084); sMockCountryName1 = parent.getString(R.string.mock_name_united_states_string); sMockPlaceName1 = parent.getString(R.string.the_greenhouse_string); sMockLoc2.setLatitude(38.996667); sMockLoc2.setLongitude(-76.9275); sMockPlaceName2 = parent.getString(R.string.berwyn_string); sMockLoc3.setLatitude(0); sMockLoc3.setLongitude(0); sMockCountryNameInvalid = ""; sMockPlaceNameInvalid = ""; System.out.println("#### finished PlaceDownloaderTask ctor"); } }
public String getDistanceToRestaurant() { SharedPreferences sharedPreferences = context.getSharedPreferences("RESTAURANT_APP", Context.MODE_PRIVATE); Location currentLocation = new Location("USER Location"); String latitude = sharedPreferences.getString("LATITUDE", null); String longitude = sharedPreferences.getString("LONGITUDE", null); if (latitude != null && longitude != null) { currentLocation.setLatitude(Double.parseDouble(latitude)); currentLocation.setLongitude(Double.parseDouble(longitude)); float distanceToRestaurant = 0f; try { Location restaurantLocation = new Location(restaurant.BrandName); restaurantLocation.setLatitude(Double.parseDouble(restaurant.Latitude)); restaurantLocation.setLongitude(Double.parseDouble(restaurant.Longitude)); distanceToRestaurant = currentLocation.distanceTo(restaurantLocation); } catch (Exception e) { // handle number formatting exception } int distanceInKm = (int) (distanceToRestaurant / 1000); return distanceInKm + " km"; } return "0 km"; }
public void onSensorChanged(SensorEvent sensorevent) { Location location = new Location(""); double d = WebUtil.getCurLat(); double d1 = WebUtil.getCurLog(); location.setLatitude(d); location.setLongitude(d1); Location location1 = new Location(""); location1.setLatitude(place.getLatitude()); location1.setLongitude(place.getLongitude()); if (!WebUtil.isLocationSet()) { Log.d("test", "NullReturn"); return; } float f = sensorevent.values[0]; float f1 = f - (new GeomagneticField( Double.valueOf(location.getLatitude()).floatValue(), Double.valueOf(location.getLongitude()).floatValue(), Double.valueOf(location.getAltitude()).floatValue(), System.currentTimeMillis())) .getDeclination(); float f2 = location.bearingTo(location1); if (f2 < 0.0F) { f2 += 360F; } float f3 = f2 - f1; if (f3 < 0.0F) { f3 += 360F; } rotateImageView(imageCompass, 0x7f0200bb, f3); if (360F >= f && (double) f >= 337.5D || 0.0F <= f && (double) f <= 22.5D) { return; } if ((double) f > 22.5D && (double) f < 67.5D) { return; } if ((double) f >= 67.5D && (double) f <= 112.5D) { return; } if ((double) f > 112.5D && (double) f < 157.5D) { return; } if ((double) f >= 157.5D && (double) f <= 202.5D) { return; } if ((double) f > 202.5D && (double) f < 247.5D) { return; } if ((double) f >= 247.5D && (double) f <= 292.5D) { return; } if ((double) f > 292.5D && (double) f < 337.5D) { return; } else { return; } }
public static float distFrom(double lat1, double lng1, double lat2, double lng2) { Location locationA = new Location("point A"); locationA.setLatitude(lat1); locationA.setLongitude(lng1); Location locationB = new Location("point B"); locationB.setLatitude(lat2); locationB.setLongitude(lng2); return locationA.distanceTo(locationB); }
// Calculates distance from a point to another public float distanceTo(LatLng current, LatLng destination) { Location from = new Location(""); from.setLatitude(current.latitude); from.setLongitude(current.longitude); Location to = new Location(""); to.setLatitude(destination.latitude); to.setLongitude(destination.longitude); return from.distanceTo(to); }
/** @return the current location */ private Location getCurrentLocation(LocationManager lm) { Location l = lm.getLastKnownLocation("gps"); if (null != l) { return l; } // getLastKnownLocation returns null if loc provider is not enabled l = new Location("gps"); l.setLatitude(42.352299); l.setLatitude(-71.063979); return l; }
public PlaceDownloaderTask(PlaceViewActivity parent) { super(); mParent = new WeakReference<PlaceViewActivity>(parent); if (!HAS_NETWORK) { mStubBitmap = BitmapFactory.decodeResource(parent.getResources(), R.drawable.stub); mockLoc1.setLatitude(37.422); mockLoc1.setLongitude(-122.084); mockLoc2.setLatitude(38.996667); mockLoc2.setLongitude(-76.9275); } }
private boolean internalSendLocation(JSONArray data, CallbackContext callbackContext) { if (mPushManager == null) { return false; } JSONObject params = null; try { params = data.getJSONObject(0); } catch (JSONException e) { e.printStackTrace(); return false; } double lat = 0; double lon = 0; try { lat = params.getDouble("lat"); lon = params.getDouble("lon"); } catch (JSONException e) { e.printStackTrace(); return false; } Location location = new Location(""); location.setLatitude(lat); location.setLongitude(lon); PushManager.sendLocation(cordova.getActivity(), location); return true; }
public GameLoopView(Context context) { super(context); // remember the context for finding resources this.context = context; score = 0; // want to know when the surface changes surfaceHolder = getHolder(); surfaceHolder.addCallback(this); // set a fixed location location = new Location("FIXED POSITION"); location.setLatitude(0); location.setAltitude(0); location.setLongitude(0); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point p = new Point(); display.getSize(p); screenWidth = p.x; screenHeight = p.y; // game loop thread thread = new GameLoopThread(); }
@Override public Location getLocation() { Location loc = new Location(LocationManager.GPS_PROVIDER); loc.setLatitude(latitude); loc.setLongitude(longitude); return loc; }
private void updateISSLocation() { if (CheckForUpdate()) { posOverlay.setLocation(currentlocation); mControl.animateTo(GetISSPos()); if (!dataSent) { if (FirstLock && !SecondLock) { posOverlay.setLock(1); dataSent = true; } if (SecondLock) { posOverlay.setLock(2); dataSent = true; } } } else if (pastlocation.getLatitude() != 0.0) { double latdist = jsonlocation.getLatitude() - pastlocation.getLatitude(); double longdist = jsonlocation.getLongitude() - pastlocation.getLongitude(); if (longdist < -300) { longdist = 180 + longdist; } double changelat = (latdist / 60) * TimeSinceLastUpdate; double changelong = (longdist / 60) * TimeSinceLastUpdate; currentlocation.setLatitude(jsonlocation.getLatitude() + changelat); currentlocation.setLongitude(jsonlocation.getLongitude() + changelong); posOverlay.setLocation(currentlocation); mControl.animateTo(GetISSPos()); } }
public Location getLocation() { Location location = new Location("Station"); location.setAltitude(stationaltitude); location.setLatitude(stationlatitude); location.setLongitude(stationlongitude); return location; }
private Location buildFakeLocation(String provider) { final Location location = new Location(provider); location.setLatitude(50.0d); location.setLongitude(30.0d); return location; }
/** recompute a lap aggregate based on locations */ private static void recomputeLap(SQLiteDatabase db, long activityId, long lap) { long sum_time = 0; double sum_distance = 0; final String[] cols = new String[] { DB.LOCATION.TIME, DB.LOCATION.LATITUDE, DB.LOCATION.LONGITUDE, DB.LOCATION.TYPE, "_id" }; Cursor c = db.query( DB.LOCATION.TABLE, cols, DB.LOCATION.ACTIVITY + " = " + activityId + " and " + DB.LOCATION.LAP + " = " + lap, null, null, null, "_id", null); if (c.moveToFirst()) { Location lastLocation = null; do { Location l = new Location("Dill poh"); l.setTime(c.getLong(0)); l.setLatitude(c.getDouble(1)); l.setLongitude(c.getDouble(2)); l.setProvider("" + c.getLong(3)); int type = c.getInt(3); switch (type) { case DB.LOCATION.TYPE_START: case DB.LOCATION.TYPE_RESUME: lastLocation = l; break; case DB.LOCATION.TYPE_END: case DB.LOCATION.TYPE_PAUSE: case DB.LOCATION.TYPE_GPS: if (lastLocation == null) { lastLocation = l; break; } sum_distance += l.distanceTo(lastLocation); sum_time += l.getTime() - lastLocation.getTime(); lastLocation = l; break; } } while (c.moveToNext()); } c.close(); ContentValues tmp = new ContentValues(); tmp.put(DB.LAP.DISTANCE, sum_distance); tmp.put(DB.LAP.TIME, (sum_time / 1000)); db.update( DB.LAP.TABLE, tmp, DB.LAP.ACTIVITY + " = " + activityId + " and " + DB.LAP.LAP + " = " + lap, null); }
public Location getLocation() { // provider name isn't necessary Location location = new Location(""); location.setLatitude(mLatitude); location.setLongitude(mLongitude); return location; }
public Streckenpunkte(Location location) { latitude = location.getLatitude(); longitude = location.getLongitude(); location = new Location("GPS"); location.setLatitude(latitude); location.setLongitude(longitude); }
private void setMarkersOptions(Location loc) { boolean visible = true; if (markersOnMap == null) { markersOnMap = new ArrayList<Marker>(); } for (Task task : TaskList.getInstance(getApplicationContext()).getTasks()) { LatLng temp = getLatLngIfPossible(task.getLocation()); if (temp != null) { Location tloc = new Location(task.getLocation()); tloc.setLatitude(temp.latitude); tloc.setLongitude(temp.longitude); float dist = tloc.distanceTo(loc); Marker tempMarker = map.addMarker( new MarkerOptions() .position(temp) .visible(visible) .title(String.valueOf(task.getTask_id())) .icon(BitmapDescriptorFactory.fromResource(R.drawable.marke_65px))); if (dist > sbRadOuter.getProgress() * 100) { tempMarker.setVisible(false); } markersOnMap.add(tempMarker); } } }
private PluginResult internalSendLocation(JSONArray data, String callbackId) { if (mPushManager == null) { return new PluginResult(Status.ERROR); } JSONObject params = null; try { params = data.getJSONObject(0); } catch (JSONException e) { e.printStackTrace(); return new PluginResult(Status.ERROR); } double lat = 0; double lon = 0; try { lat = params.getDouble("lat"); lon = params.getDouble("lon"); } catch (JSONException e) { e.printStackTrace(); return new PluginResult(Status.ERROR); } Location location = new Location(""); location.setLatitude(lat); location.setLongitude(lon); PushManager.sendLocation(cordova.getActivity(), location); return new PluginResult(Status.OK); }
private Location getLastBestLocation() { Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location locationNet = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); long GPSLocationTime = 0; if (null != locationGPS) { GPSLocationTime = locationGPS.getTime(); } long NetLocationTime = 0; if (null != locationNet) { NetLocationTime = locationNet.getTime(); } Location location; if (0 < GPSLocationTime - NetLocationTime) { location = locationGPS; } else { location = locationNet; } if (location == null) { location = new Location("Standard"); location.setLongitude(0.0); location.setLatitude(0.0); } return location; }
/** * Read location information from image. * * @param imagePath : image absolute path * @return : loation information */ public Location readGeoTagImage(String imagePath) { Location loc = new Location(""); try { ExifInterface exif = new ExifInterface(imagePath); float[] latlong = new float[2]; if (exif.getLatLong(latlong)) { loc.setLatitude(latlong[0]); loc.setLongitude(latlong[1]); } String date = exif.getAttribute(ExifInterface.TAG_DATETIME); SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); try { loc.setTime(fmt_Exif.parse(date).getTime()); } catch (java.text.ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } return loc; }
/** * This is where google play services gets connected and we can now find recent location. * * <p>Note that all the complex stuff about connecting to Google Play Services (just to get * location) is from http://developer.android.com/training/location/retrieve-current.html and I * don't actually know how to test it. * * @param connectionHint */ @Override public void onConnected(Bundle connectionHint) { Log.i( TAG, "Connected to Google Play services mLastCameraPosition==" + (mLastCameraPosition != null)); mPlayServicesConnectionStatus = true; mLastDeviceLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); // If we are now connected, but still don't have a location, use a bogus default. if (mLastDeviceLocation == null) { mLastDeviceLocation = new Location("default"); mLastDeviceLocation.setLatitude( Double.parseDouble(getResources().getString(R.string.map_default_latitude))); mLastDeviceLocation.setLongitude( Double.parseDouble(getResources().getString(R.string.map_default_longitude))); } // mMap may not yet be initialized in some cases; Connect happens before map setup. if (mMap != null) { mMap.setMyLocationEnabled(true); if (getSavedCameraPosition() == null) { setMapToCurrentLocation(); } } }
public Streckenpunkte(double latitudearg, double longitudearg) { latitude = latitudearg; longitude = longitudearg; location = new Location("GPS"); location.setLatitude(latitude); location.setLongitude(longitude); }
/** * Constructor for KeyLocation * * @param name_ Name of the key location * @param latitude_ Latitude of the key location * @param longitude_ Longitude of the key location */ public KeyLocation(String name_, double latitude_, double longitude_) { loc = new Location(""); loc.setLatitude(latitude_); loc.setLongitude(longitude_); name = name_; }
/** * Method to find the nearest location to the inputted origin Location * * @param c Cursor to set of a selection over all key location * @param origin Point to find nearest key location to (generally the user's current location) * @return Nearest key location to origin * @throws IllegalArgumentException if the Cursor does not contain the necessary latitude, * longitude, and name columns */ public static KeyLocation findNearestLoc(Cursor c, Location origin) throws IllegalArgumentException { // Initialize the nearest key location to null and the nearest_distance to infinity KeyLocation nearest = new KeyLocation(); double nearest_dist = Double.MAX_VALUE; c.moveToFirst(); do { // Iterate over all of the key locations and find the one nearest to the origin double longitude = c.getDouble(c.getColumnIndexOrThrow(KeyLocationEntry.COLUMN_LONGITUDE)); double latitude = c.getDouble(c.getColumnIndexOrThrow(KeyLocationEntry.COLUMN_LATITUDE)); Location loc = new Location(""); loc.setLongitude(longitude); loc.setLatitude(latitude); double dist = loc.distanceTo(origin); if (dist < nearest_dist) { String name = c.getString(c.getColumnIndexOrThrow(KeyLocationEntry.COLUMN_NAME)); double lt = c.getDouble(c.getColumnIndexOrThrow(KeyLocationEntry.COLUMN_LATITUDE)); double lg = c.getDouble(c.getColumnIndexOrThrow(KeyLocationEntry.COLUMN_LONGITUDE)); nearest = new KeyLocation(name, lt, lg); nearest_dist = dist; } } while (c.moveToNext()); return nearest; }
private void ReadPinsFromWebservice() { try { ArrayList<Pin> pins = HeatMapSvc.Instance() .GetMoods( GlobalSettings.Instance().getLocation(), GlobalSettings.Instance().getVisibility(), _currentMoodNumber); for (int i = 0; i < pins.size(); i++) { Location loc = new Location(""); loc.setLatitude(pins.get(i).getLatitude() * 1000000); loc.setLongitude(pins.get(i).getLongitude() * 1000000); moodPointList.put(loc, HeatMapSvc.Instance().convertPinToMoodColor(pins.get(i))); _totalNumMoods = pins.get(0).getTotalPinCount(); _currentMoodNumber = pins.get(i).getPinNumber(); } } catch (Exception e) { e.printStackTrace(); } // end catch }
/** * Fills a track point from a cursor. * * @param cursor the cursor pointing to a location. * @param indexes the cached track points indexes * @param location the track point */ private void fillTrackPoint(Cursor cursor, CachedTrackPointsIndexes indexes, Location location) { location.reset(); if (!cursor.isNull(indexes.longitudeIndex)) { location.setLongitude(((double) cursor.getInt(indexes.longitudeIndex)) / 1E6); } if (!cursor.isNull(indexes.latitudeIndex)) { location.setLatitude(((double) cursor.getInt(indexes.latitudeIndex)) / 1E6); } if (!cursor.isNull(indexes.timeIndex)) { location.setTime(cursor.getLong(indexes.timeIndex)); } if (!cursor.isNull(indexes.altitudeIndex)) { location.setAltitude(cursor.getFloat(indexes.altitudeIndex)); } if (!cursor.isNull(indexes.accuracyIndex)) { location.setAccuracy(cursor.getFloat(indexes.accuracyIndex)); } if (!cursor.isNull(indexes.speedIndex)) { location.setSpeed(cursor.getFloat(indexes.speedIndex)); } if (!cursor.isNull(indexes.bearingIndex)) { location.setBearing(cursor.getFloat(indexes.bearingIndex)); } if (location instanceof MyTracksLocation && !cursor.isNull(indexes.sensorIndex)) { MyTracksLocation myTracksLocation = (MyTracksLocation) location; try { myTracksLocation.setSensorDataSet( SensorDataSet.parseFrom(cursor.getBlob(indexes.sensorIndex))); } catch (InvalidProtocolBufferException e) { Log.w(TAG, "Failed to parse sensor data.", e); } } }
public static List<Location> getPoints(File gpxFile) throws Exception { List<Location> points; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); FileInputStream fis = new FileInputStream(gpxFile); Document dom = builder.parse(fis); Element root = dom.getDocumentElement(); NodeList items = root.getElementsByTagName("trkpt"); points = new ArrayList<Location>(); for (int j = 0; j < items.getLength(); j++) { Node item = items.item(j); NamedNodeMap attrs = item.getAttributes(); NodeList props = item.getChildNodes(); Location pt = new Location("test"); pt.setLatitude(Double.parseDouble(attrs.getNamedItem("lat").getNodeValue())); pt.setLongitude(Double.parseDouble(attrs.getNamedItem("lon").getNodeValue())); for (int k = 0; k < props.getLength(); k++) { Node item2 = props.item(k); String name = item2.getNodeName(); if (name.equalsIgnoreCase("ele")) { pt.setAltitude(Double.parseDouble(item2.getFirstChild().getNodeValue())); } if (name.equalsIgnoreCase("course")) { pt.setBearing(Float.parseFloat(item2.getFirstChild().getNodeValue())); } if (name.equalsIgnoreCase("speed")) { pt.setSpeed(Float.parseFloat(item2.getFirstChild().getNodeValue())); } if (name.equalsIgnoreCase("hdop")) { pt.setAccuracy(Float.parseFloat(item2.getFirstChild().getNodeValue()) * 5); } if (name.equalsIgnoreCase("time")) { pt.setTime((getDateFormatter().parse(item2.getFirstChild().getNodeValue())).getTime()); } } for (int y = 0; y < props.getLength(); y++) { Node item3 = props.item(y); String name = item3.getNodeName(); if (!name.equalsIgnoreCase("ele")) { continue; } pt.setAltitude(Double.parseDouble(item3.getFirstChild().getNodeValue())); } points.add(pt); } fis.close(); return points; }