public void onLocationEvent(Location location) { if (location.getAccuracy() < LOCATION_ACCURACY_THRESHOLD) { if (_locationCache.size() == 10) { _locationCache.remove(0); } _locationCache.add(location); if (isActive()) { Record record = new Record(); int lastDetectedActivity = getLastDetectedActivityType(); if (lastDetectedActivity == ON_FOOT) { lastDetectedActivity = WALKING; } record.setActivityType(lastDetectedActivity); record.setUser(ParseUser.getCurrentUser()); record.setLocation(new ParseGeoPoint(location.getLatitude(), location.getLongitude())); Account.get() .addRecord(record); } } }
public static Event getEventFromParseObject(@NonNull ParseObject parseObject){ ParseGeoPoint location = parseObject.getParseGeoPoint(Event.LOCATION); ParseFile parseFile = parseObject.getParseFile(Event.IMAGE); return new Event(parseObject.getObjectId(), parseObject.getString(Event.TITLE), parseObject.getString(Event.DESCRIPTION), location != null? location.getLatitude() : Event.INVALID_LOCATION, location != null? location.getLongitude() : Event.INVALID_LOCATION, parseObject.getString(Event.LOCATION_SUMMARY), parseObject.getString(Event.LOCATION_DESCRIPTION), parseFile != null? parseFile.getUrl() : null, parseObject.getDate(Event.INITIAL_DATE), // If end date is null, set it as initial date, so we can use it in our order by parseObject.getDate(Event.END_DATE) != null? parseObject.getDate(Event.END_DATE) : parseObject.getDate(Event.INITIAL_DATE), parseObject.getInt(Event.TYPE), parseObject.getBoolean(Event.ENABLED), (parseObject.getNumber(Event.GOING) != null)? parseObject.getNumber(Event.GOING).longValue() : 0, parseObject.getString(Event.LINK_URL), parseObject.getString(Event.LINK_TEXT), parseObject.getUpdatedAt() ); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ParseGeoPoint userLocation = mUsers.get(position) .getUserDetail() .getLocation(); LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); Marker userMarker = mMarkers.get(mUsers.get(position).getObjectId()); if (userMarker != null) { userMarker.showInfoWindow(); } }
public void bindRestaurantViewHolder() { if (restaurantHolder != null && restaurant != null) { activity.setTitle(restaurant.getName()); restaurantHolder.address.setText(restaurant.getAddressLine()); parseLocation = restaurant.getLocation(); if (parseLocation != null) { LatLng deviceLoc = LocationService.pollDeviceLocation(activity); restaurantHolder.proximity.setText(restaurant.getDistanceFromString(new ParseGeoPoint(deviceLoc.latitude,deviceLoc.longitude))); LatLng resLoc = new LatLng(parseLocation.getLatitude(), parseLocation.getLongitude()); restaurantHolder.updateMap(resLoc, restaurant.getName()); } } }
public ParseGeoPoint getLocation(Context context) { // Geisel Library - Default Location double latitude = 32.881122; double longitude = -117.237631; LocationService userLocation; if (!Build.FINGERPRINT.startsWith("generic")) { userLocation = new LocationService(context); // Is user location available and are we not running in an emulator if (userLocation.canGetLocation()) { latitude = userLocation.getLatitude(); longitude = userLocation.getLongitude(); } else { userLocation.showSettingsAlert(); } } return new ParseGeoPoint(latitude,longitude); }
private void populateMap() { final GoogleMap map = fragment.getMap(); map.setMyLocationEnabled(false); fragment.getView().post(new Runnable() { @Override public void run() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); final ParseGeoPoint pt = user.getLocation(); final LatLng latlng = new LatLng(pt.getLatitude(), pt .getLongitude()); map.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_CYAN)) .position(latlng)); builder.include(latlng); map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 13)); } }); }
private void loadMentors(final ParseGeoPoint geoPoint) { Double distance = 50.0; getProgressBar().setVisibility(View.VISIBLE); DataService.getMentors(MentorListActivity.this, geoPoint, distance, mSkill, new FindCallback<User>() { @Override public void done(final List<User> users, ParseException e) { if (e == null) { User.saveAllUsers(users); DataService.getMentees(User.getUserFacebookIds(users), new Runnable() { @Override public void run() { mentorListAdapter.addAll(User.sortedByMenteeCount(users)); getProgressBar().setVisibility(View.INVISIBLE); } }); } else { e.printStackTrace(); } setupDrawer(); } }); }
public static String getDistanceFrom(ParseUser otherUser){ //Location ParseGeoPoint myLocation = ParseUser.getCurrentUser().getParseGeoPoint(Enums.ParseKey.USER_LOCATION); ParseGeoPoint otherLocation = null; if(otherUser != null) otherLocation = otherUser.getParseGeoPoint(Enums.ParseKey.USER_LOCATION); //Calculate distance double km = 0; if(otherUser != null && otherLocation != null) km = myLocation.distanceInKilometersTo(otherLocation); else km = Math.random() * 4; //Update ui if(km < 0.5){ int m = (int)(km * 100); m = Math.max(m, 10); //10 meters at least return String.format("within %d m from you", m); } else{ return String.format("within %.1f km from you", km); } }
@Override public void onReceive(Context context, Intent intent) { try { final LocationInfo locationInfo = (LocationInfo) intent.getSerializableExtra(LocationLibraryConstants.LOCATION_BROADCAST_EXTRA_LOCATIONINFO); ParseUser.getCurrentUser().put(Enums.ParseKey.USER_LOCATION, new ParseGeoPoint(locationInfo.lastLat, locationInfo.lastLong)); Log.d("Location my", locationInfo.lastLat + " " + locationInfo.lastLong); ParseUser.getCurrentUser().saveInBackground(); } catch (Exception e){ Log.e("location error:", e.getMessage()); } if(MainActivity.gi() != null) MainActivity.gi().onLocationUpdate(); }
public void retrieveLocations(final Callback<List<LatLng>> locationsCallback) { ParseQuery<ParseObject> query = ParseQuery.getQuery("Location"); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> parseObjects, ParseException e) { if (e == null) { ArrayList<LatLng> locations = new ArrayList<LatLng>(); for (ParseObject object : parseObjects) { ParseGeoPoint geo = object.getParseGeoPoint("geo"); locations.add(new LatLng(geo.getLatitude(), geo.getLongitude())); } locationsCallback.got(locations); } } }); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); Log.e("Network Loc Service", "Service running"); AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE); Calendar timeOff9 = Calendar.getInstance(); Intent intent2 = new Intent(this,MyReceiver.class); PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT); am.set(AlarmManager.RTC_WAKEUP, timeOff9.getTimeInMillis() + 55000, sender); ParseGeoPoint pt = new ParseGeoPoint(getLocation().getLatitude(),getLocation().getLongitude()); ParseUser person = ParseUser.getCurrentUser(); if(person==null) { stopSelf(); return 0; } person.put("Geolocation",pt); person.saveInBackground(); return START_STICKY; }
@Override public void onLocationChanged(Location location) { Log.d(ServiceLocationListener.class.getSimpleName(), "Provider: " +location.getProvider() + "|" + "Lat/Lng: " + location.getLatitude() + "/" + location.getLongitude()); if (LocalDb.getInstance() != null) { mCurrentUser = LocalDb.getInstance().getCurrentUser(); UserDetail userDetail = mCurrentUser.getUserDetail(); userDetail.setLocation( new ParseGeoPoint( location.getLatitude(), location.getLongitude())); userDetail.setProvider(location.getProvider()); userDetail.setActive(true); try { userDetail.save(); } catch (ParseException e) { Log.d(ServiceLocationListener.class.getSimpleName(), e.getMessage()); } } }
public double getDistanceFrom(ParseGeoPoint location) { ParseGeoPoint restaurant = getParseGeoPoint("location"); if (restaurant == null) { return 0.0; } return location.distanceInMilesTo(restaurant); }
public static void viewUserProfile(final Context context, final long userId, final ParseGeoPoint geoPoint) { final Intent intent = new Intent(context, ViewProfileActivity.class); intent.putExtra(ViewProfileActivity.USER_ID_KEY, userId); intent.putExtra(ViewProfileActivity.LATITUDE_KEY, geoPoint.getLatitude()); intent.putExtra(ViewProfileActivity.LONGITUDE_KEY, geoPoint.getLongitude()); context.startActivity(intent); }
@Override protected void updateProfile(final User profileUser) { if (etAddress.getText() != null) { profileUser.setAddress(etAddress.getText().toString().trim()); profileUser.setAboutMe(etAboutme.getText().toString().trim()); Utils.geocode(getActivity(), new Utils.LocationParams(etAddress.getText().toString()), new Async.Block<Address>() { @Override public void call(final Address address) { if (address != null) { profileUser.setLocation(new ParseGeoPoint(address.getLatitude(), address.getLongitude())); } } }); } }
public static void getMentors(Context context, ParseGeoPoint geoPoint, Double distance, String skill, FindCallback<User> callback) { ParseQuery<User> query = User.getQuery(); query.whereEqualTo(User.IS_MENTOR_KEY, true); if(geoPoint != null) { query.whereWithinMiles(User.LOCATION_KEY, geoPoint, distance); } if(skill != null) { ArrayList<String> names = new ArrayList<String>(); if(!skill.equals("All")){ names.add(skill); query.whereContainsAll(User.MENTOR_SKILLS_KEY, names); } } query.findInBackground(callback); }
public MentorListAdapter(Context context, ParseGeoPoint geoPoint, final Persona persona, final UserDisplayMode mode) { super(context, 0); currentGeoPoint = geoPoint; this.persona = persona; this.userDisplayMode = mode; if (!sImageLoaderInitialized) { sImageLoaderInitialized = true; final ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.init(ImageLoaderConfiguration.createDefault(getContext())); } }
private boolean isInLocations(List<ParseObject> parseObjects) { if(parseObjects == null) return false; Log.d("locations", "Retrieved " + parseObjects.size() + " locations"); boolean isReleasedAtLocation = false; for(ParseObject po : parseObjects){ if(po.getBoolean(Enums.ParseKey.PLACE_RELEASED)) { ParseGeoPoint point = po.getParseGeoPoint(Enums.ParseKey.USER_LOCATION); double radius = po.getDouble(Enums.ParseKey.PLACE_RADIUS); //KM float[] results = new float[3]; Location.distanceBetween(point.getLatitude(), point.getLongitude(), locationInfo.lastLat, locationInfo.lastLong, results); Log.d("distance", Float.toString(results[0])); if(results[0] <= radius * 1000) { isReleasedAtLocation = true; break; } } } if(!isReleasedAtLocation) { showNotReleasedAtLocationDialog(); dismissDialog(); return false; } else return true; }
public static int getDistanceInMeters(ParseUser otherUser){ //Location ParseGeoPoint myLocation = ParseUser.getCurrentUser().getParseGeoPoint(Enums.ParseKey.USER_LOCATION); ParseGeoPoint otherLocation = null; if(otherUser != null) otherLocation = otherUser.getParseGeoPoint(Enums.ParseKey.USER_LOCATION); //Calculate distance double km = 0; if(otherUser != null && otherLocation != null) km = myLocation.distanceInKilometersTo(otherLocation); return (int)(km * 1000); }
@Override public void readAllInArea(final double latitude, final double longitude, final double maxDistance, final PointOfInterestReadHandler handler) { ParseGeoPoint userLocation = new ParseGeoPoint(latitude, longitude); ParseQuery<ParseObject> query = ParseQuery.getQuery(POI_TABLE); query.whereEqualTo(DELETED, false); query.whereWithinKilometers(LOCATION, userLocation, maxDistance); query.setLimit(POINTS_AMOUNT_LOMIT); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> objects, ParseException e) { if (e == null) { List<PointLocation> points = new ArrayList<PointLocation>(); for (ParseObject object : objects) { points.add(getLocation(object)); } handler.readAllInAreaCompleted(points); } else { String errorMessage = String.format(Locale.US, "readAllInArea failed with parameters: (latitude=%f, longitude=%f, maxDistance=%f)", latitude, longitude, maxDistance); Log.e(LOG_TAG, errorMessage, e); handler.readAllInAreaFailed(latitude, longitude, maxDistance, e); } } }); }
public Event(String message, ParseGeoPoint coordinates, String category, String authorHash, Date date, List<String> respondentsHash) { this.message = message; this.coordinates = coordinates; this.category = category; this.authorHash = authorHash; this.date = date; this.respondentsHash = respondentsHash; }
public static void getEventsInRadius(double lan, double lng) { final ArrayList<Event> events = new ArrayList<Event>(); ParseQuery<ParseObject> query = ParseQuery.getQuery(EVENT_TABLE_NAME); query.whereWithinMiles(COORDINATES_COL_NAME, new ParseGeoPoint(lan, lng), EVENTS_VISIBILITY_RADIUS_IN_MILES); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> parseObjects, ParseException e) { if (e == null) { for (int i = 0; i < parseObjects.size(); i++) { ParseObject po = parseObjects.get(i); Event ev = new Event( po.getString(MESSAGE_COL_NAME), po.getParseGeoPoint(COORDINATES_COL_NAME), po.getString(CATEGORY_COL_NAME), po.getString(AUTHOR_HASH_COL_NAME), po.getDate(DATE_COL_NAME), po.<String>getList(RESPONDENTS_HASH_COL_NAME) ); ev.setHash(po.getObjectId()); events.add(ev); } bus.post(events); } } }); }
public static void searchEventsInRadius(String key, Double lan, Double lng) { final ArrayList<Event> events = new ArrayList<Event>(); ParseQuery<ParseObject> query = ParseQuery.getQuery(EVENT_TABLE_NAME); query.whereWithinMiles(COORDINATES_COL_NAME, new ParseGeoPoint(lan, lng), EVENTS_VISIBILITY_RADIUS_IN_MILES); query.whereContains(MESSAGE_COL_NAME, key); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> parseObjects, ParseException e) { if (e == null) { for (int i = 0; i < parseObjects.size(); i++) { ParseObject po = parseObjects.get(i); Event ev = new Event( po.getString(MESSAGE_COL_NAME), po.getParseGeoPoint(COORDINATES_COL_NAME), po.getString(CATEGORY_COL_NAME), po.getString(AUTHOR_HASH_COL_NAME), po.getDate(DATE_COL_NAME), po.<String>getList(RESPONDENTS_HASH_COL_NAME) ); ev.setHash(po.getObjectId()); events.add(ev); } searchEventResult.clear(); searchEventResult.addAll(events); bus.post(STATUS_SEARCH_SUCCESS); } else { bus.post(STATUS_SEARCH_FAIL); } } }); }
/** * updateLocation * * @param latitude * @param longitude * @param forceUpdate whether we should force an update * @return true if location was updated, false otherwise */ public boolean updateLocation(double latitude, double longitude, boolean forceUpdate) { boolean updated = false; if (forceUpdate || shouldUpdateLocation(latitude, longitude)) { ParseGeoPoint geoPoint = new ParseGeoPoint(latitude, longitude); parseUser.put("location", geoPoint); parseUser.put("locationLastUpdatedAt", new Date()); parseUser.saveEventually(); updated = true; } return updated; }
public Sighting(Species speciesName){ this.species = speciesName; this.date = new Date(); ParseGeoPoint myDot = ParseUtils.getLastKnownLocation(); this.latitude = myDot.getLatitude() ; this.longitude = myDot.getLongitude(); }
public void setGeolocation(Location location) { put("geolocation", new ParseGeoPoint( location.getLatitude(), location.getLongitude())); }
public ParseGeoPoint getOriginLocation() { return getParseGeoPoint("date"); }
@Override public ParseGeoPoint getGeoPoint() { return getParseGeoPoint("placedAt"); }
@Override public ParseGeoPoint getGeoPoint() { return new ParseGeoPoint(lat, lon); }
public static LatLng geoPointToLatLng(ParseGeoPoint geoPoint) { return new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude()); }
public static ParseGeoPoint latLngToParseGeo(LatLng latLng) { return new ParseGeoPoint(latLng.latitude, latLng.longitude); }
public ParseGeoPoint getLocation() { return getParseGeoPoint(KEY_START_POINT); }
public ParseGeoPoint getLocation() { return getParseGeoPoint(KEY_LOCATION); }
public ParseGeoPoint getLocation() { return getParseGeoPoint("location"); }
public void setLocation(ParseGeoPoint value) { put("location", value); }
public void setCurrentLatLng(@Nullable LatLng currentLatLng) { boolean shouldPostEvent = false; if (this.currentLatLng == null && currentLatLng != null) { shouldPostEvent = true; } if (currentLatLng == null) { UserPreferences.setLatitude(Event.INVALID_LOCATION); UserPreferences.setLongitude(Event.INVALID_LOCATION); } else { if (LoginManager.getInstance().isLoggedIn()) { if (this.currentLatLng == null || distance((float) this.currentLatLng.latitude, (float) this.currentLatLng.longitude, (float) currentLatLng.latitude, (float) currentLatLng.longitude) > DISTANCE_THRESHOLD) { // If we don't have a current latlng yet, or if the new received distance is from a distance greater than the threshold, update // ParseUser object and UserPreferences UserPreferences.setLatitude(currentLatLng.latitude); UserPreferences.setLongitude(currentLatLng.longitude); final double previousLatitude = this.currentLatLng != null ? this.currentLatLng.latitude : Event.INVALID_LOCATION; final double previousLongitude = this.currentLatLng != null ? this.currentLatLng.longitude : Event.INVALID_LOCATION; ParseUser currentUser = ParseUser.getCurrentUser(); currentUser.put("location", new ParseGeoPoint(currentLatLng.latitude, currentLatLng.longitude)); currentUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { // Something bad occurred. Rollback UserPreferences UserPreferences.setLatitude(previousLatitude); UserPreferences.setLongitude(previousLongitude); Timber.d("Rolling back saved locations in UserPreferences because could not get it saved in Parse."); } } }); } } else { UserPreferences.setLatitude(currentLatLng.latitude); UserPreferences.setLongitude(currentLatLng.longitude); } } this.currentLatLng = currentLatLng; if (shouldPostEvent) { // Only post event after this..currentLatLng has the right value EventBus.getDefault().post(new FirstLocationEncounteredEvent()); } }
@Override protected Void doInBackground(String... params) { String username = params[0]; String password = params[1]; String email = params[2]; User newUser = new User(); newUser.setUsername(username); newUser.setPassword(password); newUser.setEmail(email); // Retrieve user current Location UserDetail userDetail = new UserDetail(); Location location = getLocation(); if (location != null) { userDetail.setLocation(new ParseGeoPoint(location.getLatitude(), location.getLongitude())); } else { userDetail.setLocation(new ParseGeoPoint(0, 0)); } userDetail.setProvider(LocationManager.NETWORK_PROVIDER); // Create an empty follow row Follow emptyFollow = new Follow(); emptyFollow.setFollowers(new ArrayList<User>()); emptyFollow.setFollowings(new ArrayList<User>()); try { // Save the new follow table emptyFollow.save(); newUser.setFollow(emptyFollow); // Save empty location (0,9) userDetail.save(); newUser.setUserDetail(userDetail); // sign-up the new user newUser.signUp(); goToMain(newUser); } catch (final ParseException e) { runOnUiThread(new Runnable() { @Override public void run() { NotificationHelper.alert(RegisterActivity.this, getString(R.string.dialog_error_title), e.getMessage()); } }); } return null; }
public ParseGeoPoint getLocation() { return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); }
public void setLocation(ParseGeoPoint location) { put(Constants.USER_DETAIL_COL_LOCATION, location); }
public String getDistanceFromString(ParseGeoPoint location) { return String.format("%.1f", getDistanceFrom(location)) + " mi"; }