Missing records in polygon geoquery (swift)

Hi, im getting missing records when doing a geo-query from my swift app.

When i add new JSON records, sometimes they are query-able, sometimes not.
I checked my api key, my admin key (im using admin key temporarily).

Some things to know:

  • im running AlgoliaSearch-Client-Swift (4.8.2)
  • im still running swift 3 and xcode 8.3.2
  • my query location is in the UK - haslemere (if you use geohashing - i hear there is problems at the prime meridian)
  • im currently in china using a vpn (in case there is a timeout, but i checked and it says exhaustive nb hits = 1)
  • im running the free version

I assume it is on my end as i am relatively new to coding, however i cant seem to find out why. I will attach code in case it helps.

Any help is greatly appreciated, thanks in advance.

    func searchInsidepolygon() {
    
    let index = client.index(withName: "location_RESTAURANTS")
    let polygon = [LatLng(lat: 51.125096, lng: -0.819169), LatLng(lat: 51.121080, lng: -0.624313), LatLng(lat: 51.030782, lng: -0.876989), LatLng(lat: 50.993293, lng: -0.608689)]
    let query = Query(query: "")
    query.insidePolygon = [polygon]
    
    
    index.search(query, completionHandler: { (res, error) in
        print("algolia hits")
        dump(res)
        
        if let queryResult = res {
            let json = JSON(queryResult)
            for (key, subJson) in json["hits"] {
                if let objectID = subJson["objectID"].string {
                    print("objectID: \(objectID)")
                        if let geoloc = subJson["_geoloc"].dictionary {
                            let lat = geoloc["lat"]?.double
                            let lng = geoloc["lng"]?.double
                            // CARE FORCE UNWRAPPING OPTIONALS, IS THIS SAFE?
                            let restLocation = LocationModel(lat: lat!, lng: lng!, objectID: objectID)
                            self.locationModelArray.append(restLocation)
                        }
                }
            }
            print("algolia hits")
            dump(self.locationModelArray)
        }
    })
    
}

Hi @alexahlen.

Could you give us a sample with the latitude / longitude of your data that doesn’t gets fetched?

Thanks!

I tried your coordinates and this is how it looks like:

Try changing to order of the coordinates to this to have a proper polygon:
[LatLng(lat: 51.125096, lng: -0.819169), LatLng(lat: 51.030782, lng: -0.876989), LatLng(lat: 50.993293, lng: -0.608689), LatLng(lat: 51.121080, lng: -0.624313)]

Here’s a link so you can visualise the polygon: https://jsfiddle.net/8kh12aLz/1/

So simple! works perfectly thank you very much.
And that tool is very helpful as well ive been wondering how the search area is affected by various factors, this makes it very clear.

Thanks again

Alex