@Override public ParseGeoPoint then(Task<Location> task) { Location location = task.getResult(); return new ParseGeoPoint(location.getLatitude(), location.getLongitude()); } });
@Test public void testConstructors() { ParseGeoPoint point = new ParseGeoPoint(); assertEquals(0, point.getLatitude(), 0); assertEquals(0, point.getLongitude(), 0); double lat = 1.0; double lng = 2.0; point = new ParseGeoPoint(lat, lng); assertEquals(lat, point.getLatitude(), 0); assertEquals(lng, point.getLongitude(), 0); ParseGeoPoint copy = new ParseGeoPoint(point); assertEquals(lat, copy.getLatitude(), 0); assertEquals(lng, copy.getLongitude(), 0); }
/** * Creates a new point with the specified latitude and longitude. * * @param latitude The point's latitude. * @param longitude The point's longitude. */ public ParseGeoPoint(double latitude, double longitude) { setLatitude(latitude); setLongitude(longitude); }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof ParseGeoPoint)) { return false; } if (obj == this) { return true; } return ((ParseGeoPoint) obj).getLatitude() == latitude && ((ParseGeoPoint) obj).getLongitude() == longitude; }
@Test public void testEquals() { ParseGeoPoint pointA = new ParseGeoPoint(30d, 50d); ParseGeoPoint pointB = new ParseGeoPoint(30d, 50d); ParseGeoPoint pointC = new ParseGeoPoint(45d, 45d); assertTrue(pointA.equals(pointB)); assertTrue(pointA.equals(pointA)); assertTrue(pointB.equals(pointA)); assertFalse(pointA.equals(null)); assertFalse(pointA.equals(true)); assertFalse(pointA.equals(pointC)); }
@Test public void testParcelable() { ParseGeoPoint point = new ParseGeoPoint(30d, 50d); Parcel parcel = Parcel.obtain(); point.writeToParcel(parcel, 0); parcel.setDataPosition(0); point = ParseGeoPoint.CREATOR.createFromParcel(parcel); assertEquals(point.getLatitude(), 30d, 0); assertEquals(point.getLongitude(), 50d, 0); } }
@Override public void done(Profile profile, ParseException e) { if (e == null && profile != null) { // build object ParseGeoPoint pLocation = new ParseGeoPoint(); pLocation.setLatitude(latLng.latitude); pLocation.setLongitude(latLng.longitude); profile.setLocation(pLocation); // save to parse and pin locally for offline mode final ArrayList<Profile> profiles = new ArrayList<>(); profiles.add(profile); profile.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Log.d("LOCATION_SAVED", "on profile"); LocalDataStore.unpinAndRepin(profiles, LocalDataStore.PROFILE_PIN); } else { Log.d("LOCATION_NOT_SAVED", e.toString()); } } }); // TODO: Provide feedback to user if update fails } else if (profile == null) { Log.d("PROFILE_NULL", ""); } else { Log.d("PROFILE_ERROR", e.toString()); } } });
@Override public void done(List<ParseObject> objects, ParseException e) { if ( e == null){ if(objects.size() > 0){ listViewContent.clear(); usernames.clear(); latitudes.clear(); longitudes.clear(); for (ParseObject object : objects){ Double distanceInMiles = userLocation.distanceInMilesTo((ParseGeoPoint) object.get("requesterLocation")); Double distaneOneDP = (double) Math.round(distanceInMiles *10) / 10; listViewContent.add(String.valueOf(distaneOneDP)+ " miles"); usernames.add(object.getString("requesterUsername")); latitudes.add(object.getParseGeoPoint("requesterLocation").getLatitude()); longitudes.add(object.getParseGeoPoint("requesterLocation").getLongitude()); } arrayAdapter.notifyDataSetChanged(); } } } });
object.put("file", file); ParseGeoPoint point = new ParseGeoPoint(30d, 50d); object.put("point", point); newRel.hasKnownObject(related); assertEquals(newObject.getParseFile("file").getUrl(), object.getParseFile("file").getUrl()); assertEquals(newObject.getParseGeoPoint("point").getLatitude(), object.getParseGeoPoint("point").getLatitude(), 0);
@Override public void writeToParcel(Parcel dest, int flags) { writeToParcel(dest, ParseParcelEncoder.get()); }
/** * Creates a copy of {@code point}; * * @param point The point to copy. */ public ParseGeoPoint(ParseGeoPoint point) { this(point.getLatitude(), point.getLongitude()); }
((ParseGeoPoint) object).writeToParcel(dest, this);
@Override public ParseGeoPoint then(Task<Location> task) { Location location = task.getResult(); return new ParseGeoPoint(location.getLatitude(), location.getLongitude()); } });
@Test public void testGetParseGeoPointKeyExist() { final ParseGeoPoint geoPoint = new ParseGeoPoint(44.484, 26.029); ParseGeoPoint geoPointAgain = new ParseGeoPoint(45.484, 27.029); final Map<String, Object> params = new HashMap<>(); params.put("key", geoPoint); ParseConfig config = new ParseConfig(params); ParseGeoPoint geoPointConfig = config.getParseGeoPoint("key"); assertEquals(geoPoint.getLongitude(), geoPointConfig.getLongitude(), 0.0001); assertEquals(geoPoint.getLatitude(), geoPointConfig.getLatitude(), 0.0001); assertSame(geoPointConfig, config.getParseGeoPoint("key", geoPointAgain)); }
/** * Get converts coordinate to JSONArray. */ protected JSONArray coordinatesToJSONArray() throws JSONException { JSONArray points = new JSONArray(); for (ParseGeoPoint coordinate : coordinates) { JSONArray point = new JSONArray(); point.put(coordinate.getLatitude()); point.put(coordinate.getLongitude()); points.put(point); } return points; }
/** * Creates a new point instance from a {@link Parcel} using the given {@link ParseParcelDecoder}. * The decoder is currently unused, but it might be in the future, plus this is the pattern we * are using in parcelable classes. * * @param source the parcel * @param decoder the decoder */ ParseGeoPoint(Parcel source, ParseParcelDecoder decoder) { setLatitude(source.readDouble()); setLongitude(source.readDouble()); }
@Override public ParseGeoPoint createFromParcel(Parcel source) { return new ParseGeoPoint(source, ParseParcelDecoder.get()); }
final ParseFile file = new ParseFile( new ParseFile.State.Builder().name("image.png").url("http://yarr.com/image.png").build()); final ParseGeoPoint geoPoint = new ParseGeoPoint(44.484, 26.029); final List<Object> list = new ArrayList<Object>() {{ add("foo"); assertEquals(file.getName(), fileAgain.getName()); ParseGeoPoint geoPointAgain = (ParseGeoPoint) decodedDiskConfigParameters.get("geoPoint"); assertEquals(geoPoint.getLatitude(), geoPointAgain.getLatitude(), 0.0000001); assertEquals(geoPoint.getLongitude(), geoPointAgain.getLongitude(), 0.0000001); List<Object> listAgain = (List<Object>) decodedDiskConfigParameters.get("array"); assertArrayEquals(list.toArray(), listAgain.toArray());
ParseGeoPoint target = (ParseGeoPoint) value; if (northeast.getLongitude() < southwest.getLongitude()) { throw new ParseException(ParseException.INVALID_QUERY, "whereWithinGeoBox queries cannot cross the International Date Line."); if (northeast.getLatitude() < southwest.getLatitude()) { throw new ParseException(ParseException.INVALID_QUERY, "The southwest corner of a geo box must be south of the northeast corner."); if (northeast.getLongitude() - southwest.getLongitude() > 180) { throw new ParseException(ParseException.INVALID_QUERY, "Geo box queries larger than 180 degrees in longitude are not supported. " return (target.getLatitude() >= southwest.getLatitude() && target.getLatitude() <= northeast.getLatitude() && target.getLongitude() >= southwest.getLongitude() && target.getLongitude() <= northeast.getLongitude());
@Test(expected = IllegalArgumentException.class) public void testThreePointMinimum() { ParseGeoPoint p1 = new ParseGeoPoint(0, 0); ParseGeoPoint p2 = new ParseGeoPoint(0, 1); List<ParseGeoPoint> points = Arrays.asList(p1, p2); ParsePolygon polygon = new ParsePolygon(points); }