Quantcast
Channel: Azure Mobile Apps forum
Viewing all articles
Browse latest Browse all 3756

Trying to query Microsoft Azure table on iOS using NSPredicate and MSQuery

$
0
0

Hi! I am struggling with trying to query the Microsoft Azure database using NSPredicate and MSQuery for iOS. I am following the code written at the below link: 

http://azure.microsoft.com/en-us/documentation/articles/mobile-services-ios-how-to-use-client-library/#querying

However, when I run my code, I am getting no data, even though there is clearly data in between the two ranges of latitude and longitude. Do you know where the problem is? I think it is because I am combining both MSQuery and NSPredicate, even though the example above does not do so, but I am not sure how to get the same data using only one. I have copied my code below for your convenience. Thanks for your help!

self.client = [(AppDelegate *) [[UIApplicationsharedApplication] delegate] client];

self.table = [self.clienttableWithName:@"Item"];

self.latitude = 41.504341;

self.longitude = -81.608384;

NSPredicate *predicate = [NSPredicate

                             predicateWithFormat:@"event_latitude >= %d AND event_latitude < %d AND event_longitude >= %d AND event_longitude < %d"

                              ,self.latitude - .0218

                              ,self.latitude+ .0218

                              ,self.longitude - 2.414/(111.23 *cos(self.latitude))

                              ,self.longitude+ 2.414/(111.23 *cos(self.latitude))

                              ];

MSQuery *query = [self.tablequeryWithPredicate: predicate];

query.fetchLimit = 50;

[query orderByDescending:(@"event_start")];

_itemsFromDatabase =[[NSDictionaryalloc] init];

    [query readWithCompletion:^(MSQueryResult *result,NSError *error) {

        if(error) { // error is nil if no error occured

            NSLog(@"ERROR %@", error);

        }

        else{

            NSLog(@"HELLO2");

            for(NSDictionary *itemin result.items) { // items is NSArray of records that match query

                NSLog(@"Todo Item: %@", [itemobjectForKey:@"text"]);

            }

            _itemsFromDatabase : [result.itemsmutableCopy];

        }

    }];

Just to clarify, there is no error from this code. HELLO2 is outputted, however, there is no data to go along with it (when clearly there should be). I have outputted the latitude and longitude minimums and manually checked and multiple events should be being returned. Thanks again for your help!

    



Viewing all articles
Browse latest Browse all 3756

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>