Can't get geo-queries in iOS to work

95 views
Skip to first unread message

Ivan Lugo

unread,
Feb 24, 2014, 8:40:09 PM2/24/14
to mobile-c...@googlegroups.com
Enter code here...

Hello there - first timer here, great group you have. Thanks in advance for taking the time out to help!

I'm trying to get a set of coordinates that are stuck in a geoJSON formatted document in the CBL database to compare themselves to a tapped point on a map, but it's just not working for me. I've tried changing the bounding coordinates of the map, the emitted keys (I tried the coordinates themselves, and then just the geoJSON geometry tag itself), but nothing is ever enumerated for me to iterate over, which I'm supposing means there is nothing found. Any idea what I'm doing wrong?

    CBLView *view = [self.database viewNamed:@"taps"];
    CBLGeoRect rect = (CBLGeoRect){{tapPoint.latitude - .0005, tapPoint.longitude - .0005}, {tapPoint.latitude + .0005, tapPoint.longitude + .0005} };
    
    [view setMapBlock: MAPBLOCK({
        id place = [doc objectForKey:@"geometry"];
        if(place)
        {
            //NSLog(@"%@", place);
            NSDictionary* temp = [doc valueForKeyPath:@"geometry.coordinates"];
            //emit(CBLGeoJSONKey(doc[@"coordinates"]), doc[@"place"]);
            
            NSLog(@"%@", temp);
            emit(temp, doc[@"place"]);
        }
    }) version: @"1.0"];
    
    CBLQuery* query = [[self.database viewNamed: @"taps"] createQuery];
    //query.boundingBox = (CBLGeoRect){{tapPoint.latitude - .0005, tapPoint.longitude - .0005}, {tapPoint.latitude + .0005, tapPoint.longitude + .0005} };
    query.boundingBox = (CBLGeoRect){{tapPoint.latitude + 5, tapPoint.longitude - 5}, {tapPoint.latitude + 5, tapPoint.longitude + 5} };
    CBLQueryEnumerator *rowEnum = [query run: &error];
    
    for (CBLGeoQueryRow* row in rowEnum)
    {
        NSLog(@"What did I find? ... %@", ((CBLGeoQueryRow*)row).geometry);
    }



Jens Alfke

unread,
Feb 25, 2014, 1:48:23 AM2/25/14
to mobile-c...@googlegroups.com
Well, you have to use CBLGeoJSONKey to generate the key to emit, otherwise it won’t be treated as a geo coordinate.
Also, the parameter to that function needs to be an object in GeoJSON format, of type “Polygon” or “Point”. (If it isn’t, a warning will be logged.)
Hope that helps…

—Jens

Ivan Lugo

unread,
Feb 27, 2014, 1:02:21 PM2/27/14
to mobile-c...@googlegroups.com
Hey there Jens, and thanks for the help!

It was my very, very silly mistake. I originally emitted said key, but in a desperate attempt to get it to to work, I tried emitting different values. It turns out I wasn't really do the right type of bounding box. The geoJSON I created from geojson.io has the lat/long swapped from the normal order. So, since I trying to set the lat/long from that data, my tap was looking for some strange place in Antarctica that, of course, has no objects drawn there.. oh my. Swapping the bounding box coordinates was the fix.
Reply all
Reply to author
Forward
0 new messages