Skip to content
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

GeoQuerie's withinPolygon are not working properly #380

Closed
alexvenom opened this issue Jul 12, 2022 · 2 comments · Fixed by #381
Closed

GeoQuerie's withinPolygon are not working properly #380

alexvenom opened this issue Jul 12, 2022 · 2 comments · Fixed by #381
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@alexvenom
Copy link

alexvenom commented Jul 12, 2022

Issue Description

GeoQueries running with withinPolygon constraint do not work and return error -1 (Unknown server Error) or 1 (Internal Server Error), either when used with a Polygon such as:

let query = City.query(withinPolygon(key: "location", polygon: myPolygon))

or with an array of GeoPoints such as:

let query = City.query(withinPolygon(key: "location", points: [geoPoint1, geoPoint2, geoPoint3, geoPoint4]))

Steps to reproduce

Parse 4.5.0 running at Back4App
Parse-Swift in the latest version added to the project using SPM
Class with GeoPoint property contained in the area of Polygon or array of GeoPoints

Actual Outcome

Parse Error either Error -1 (Unknown Server Error) or 1 (Internal Server Error)
Message from Debug Print:

Error querying: ParseError code=1 error=Internal server error.

Expected Outcome

A list of objects contained in the current Polygon or GeoPoint Array.
Same code with same coordinates when used with the JS SDK return objects correctly.

JS SDK output:

{"location":{"__type":"GeoPoint","latitude":-15.79485821477289,"longitude":-47.88391074690196},"name":"Brasília","createdAt":"2022-06-20T01:53:03.809Z","updatedAt":"2022-06-20T01:53:03.809Z","objectId":"7gd45OXwIi"}

Environment

Client

  • Parse Swift SDK version: 4.7.0 installed via SPM
  • Xcode version: XCode 13.3
  • Operating system (iOS, macOS, watchOS, etc.): Mac OSX Monterey 12.3.1
  • Operating system version: 12.3.1
  • Emulator: iOS 14.0 image

Server

  • Parse Server version: 4.5.0
  • Operating system: Linux
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Back4App

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 3.6
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Back4App

Logs

Error querying: ParseError code=1 error=Internal server error.

Code to Reproduce

Assuming you have a Class called "City" which contains a property named "location" that has a valid GeoPoint contained in the Polygon or array of GeoPoints.
The code below uses an array of GeoPoints, but the behavior is the same with a Polygon.

private func withinPolygon_query() {
        do {
            let geoPoint1 = try ParseGeoPoint(latitude: 90.0, longitude: -180.0)
            let geoPoint2 = try ParseGeoPoint(latitude: -90.0, longitude: -180.0)
            let geoPoint3 = try ParseGeoPoint(latitude: 90.0, longitude: 180.0)
            let geoPoint4 = try ParseGeoPoint(latitude: -90.0, longitude: 180.0)
            
            let query = City.query(withinPolygon(key: "location", points: [geoPoint1, geoPoint2, geoPoint3, geoPoint4]))
            
            query.find { results in
                switch results {
                    case .success(let cities):
                        cities.forEach { (city) in
                            print("Found City with objectId \"\(city.objectId!)\"")
                        }
                    case .failure(let error):
                        print("Error querying: \(error)")
                }
            }
        } catch let error as ParseError {
            print("Failed to instantiate vertices: \(error.message)")
        } catch {
            print("Failed to instantiate vertices: \(error.localizedDescription)")
        }
    }

Same implementation in Node.JS using the JS SDK, which responds correctly with all objects:

async function run(){
    let geoPoint1 = new Parse.GeoPoint({latitude: 90.0, longitude: -180.0});
    let geoPoint2 = new Parse.GeoPoint({latitude: -90.0, longitude: -180.0});
    let geoPoint3 = new Parse.GeoPoint({latitude: 90.0, longitude: 180.0});
    let geoPoint4 = new Parse.GeoPoint({latitude: -90.0, longitude: 180.0});

    const query = new Parse.Query("City");
    query.withinPolygon("location", [geoPoint1, geoPoint2, geoPoint3, geoPoint4]);
    const results = await query.find();
    results.forEach((result) => {
        console.log(JSON.stringify(result));
    });
}
@parse-github-assistant
Copy link

parse-github-assistant bot commented Jul 12, 2022

Thanks for opening this issue!

  • ❌ Please edit your post and use the provided template when creating a new issue. This helps everyone to understand your post better and asks for essential information to quicker review the issue.

@cbaker6 cbaker6 added the type:bug Impaired feature or lacking behavior that is likely assumed label Jul 12, 2022
@cbaker6 cbaker6 linked a pull request Jul 13, 2022 that will close this issue
7 tasks
@cbaker6
Copy link
Contributor

cbaker6 commented Jul 13, 2022

Thanks for reporting this will be fixed by #381

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants