-
-
Notifications
You must be signed in to change notification settings - Fork 515
Add Android Polygon and Full Text #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,42 @@ This point is then stored in the object as a regular field. | |
placeObject.put("location", point); | ||
``` | ||
|
||
To retrieved `ParseGeoPoint` from an object. | ||
|
||
```java | ||
placeObject.getParseGeoPoint("location"); | ||
``` | ||
|
||
## ParsePolygon | ||
|
||
Parse allows you to associate polygon coordinates with an object. Adding a `ParsePolygon` to a `ParseObject` allows queries to determine whether a `ParseGeoPoint` is within a `ParsePolygon` or if a `ParsePolygon` contains a `ParseGeoPoint` . | ||
|
||
* `ParsePolygon` must contain at least three coordinates. | ||
|
||
For example, to create a polygon with coordinates (0, 0), (0, 1), (1, 1), (1, 0). | ||
|
||
```java | ||
List<ParseGeoPoint> points = new ArrayList<ParseGeoPoint>(); | ||
points.add(new ParseGeoPoint(0,0)); | ||
points.add(new ParseGeoPoint(0,1)); | ||
points.add(new ParseGeoPoint(1,1)); | ||
points.add(new ParseGeoPoint(1,0)); | ||
|
||
ParsePolygon polygon = new ParsePolygon(points); | ||
``` | ||
|
||
This point is then stored in the object as a regular field. | ||
|
||
```java | ||
placeObject.put("bounds", polygon); | ||
``` | ||
|
||
To retrieved `ParsePolygon` from an object. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing here. |
||
|
||
```java | ||
placeObject.getParsePolygon("bounds"); | ||
``` | ||
|
||
## Geo Queries | ||
|
||
Now that you have a bunch of objects with spatial coordinates, it would be nice to find out which objects are closest to a point. This can be done by adding another restriction to `ParseQuery` using `whereNear`. Getting a list of ten places that are closest to a user may look something like: | ||
|
@@ -42,9 +78,46 @@ query.whereWithinGeoBox("location", southwestOfSF, northeastOfSF); | |
query.findInBackground(new FindCallback<ParseObject>() { ... }); | ||
``` | ||
|
||
You can query for whether an object lies within or on a polygon of `Parse.GeoPoint`. | ||
|
||
```java | ||
ParseGeoPoint point = new ParseGeoPoint(0.5, 0.5); | ||
ParseQuery<ParseObject> query = ParseQuery.getQuery("PlaceObject"); | ||
query.wherePolygonContains("location", point); | ||
``` | ||
|
||
You can also query for whether an object `Parse.Polygon` contains a `Parse.GeoPoint`. | ||
|
||
```java | ||
ParseGeoPoint point = new ParseGeoPoint(0.5, 0.5); | ||
ParseQuery<ParseObject> query = ParseQuery.getQuery("PlaceObject"); | ||
query.wherePolygonContains("location", point); | ||
``` | ||
|
||
To efficiently find if a `ParsePolygon` contains a `ParseGeoPoint` without querying use `containsPoint`. | ||
|
||
```java | ||
List<ParseGeoPoint> points = new ArrayList<ParseGeoPoint>(); | ||
points.add(new ParseGeoPoint(0, 0)); | ||
points.add(new ParseGeoPoint(0, 1)); | ||
points.add(new ParseGeoPoint(1, 1)); | ||
points.add(new ParseGeoPoint(1, 0)); | ||
|
||
ParseGeoPoint inside = new ParseGeoPoint(0.5, 0.5); | ||
ParseGeoPoint outside = new ParseGeoPoint(10, 10); | ||
|
||
ParsePolygon polygon = new ParsePolygon(points); | ||
|
||
// Returns True | ||
polygon.containsPoint(inside); | ||
|
||
// Returns False | ||
polygon.containsPoint(outside); | ||
``` | ||
|
||
## Parcelable | ||
|
||
As most public facing components of the SDK, `ParseGeoPoint` implements the `Parcelable` interface. This means you can retain a `ParseGeoPoint` during configuration changes, or pass it to other components of the app through `Bundles`. To achieve this, depending on the context, use either `Parcel#writeParcelable(Parcelable, int)` or `Bundle#putParcelable(String, Parcelable)`. For instance, in an Activity, | ||
As most public facing components of the SDK, `ParseGeoPoint` and `ParsePolygon` implements the `Parcelable` interface. This means you can retain a `ParseGeoPoint` and `ParsePolygon` during configuration changes, or pass it to other components of the app through `Bundles`. To achieve this, depending on the context, use either `Parcel#writeParcelable(Parcelable, int)` or `Bundle#putParcelable(String, Parcelable)`. For instance, in an Activity, | ||
|
||
```java | ||
private ParseGeoPoint point; | ||
|
@@ -54,7 +127,7 @@ protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | ||
outState.putParcelable("point", point); | ||
} | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
if (savedInstanceState != null) { | ||
|
@@ -63,6 +136,23 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { | |
} | ||
``` | ||
|
||
```java | ||
private ParsePolygon polygon; | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
outState.putParcelable("polygon", polygon); | ||
} | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
if (savedInstanceState != null) { | ||
polygon = (ParsePolygon) savedInstanceState.getParcelable("polygon"); | ||
} | ||
} | ||
``` | ||
|
||
## Caveats | ||
|
||
At the moment there are a couple of things to watch out for: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to correct retrieved to retrieve. To improve the wording could be