0

I've searched a lot but I can't find what I'm doing wrong. I'm trying to get 2 numbers that are stored in Firebase (uses a json file) and then create google maps markers with one of these numbers being the latitude and the other the longitude.

 __block int i =0;
while (i < 5) {
    i++;
    NSString *url = [NSString stringWithFormat:@"---myfirebaseurl---", i];

    Firebase *ref = [[Firebase alloc] initWithUrl:url];
    [ref observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {

        if (snapshot.value == [NSNull null]){

            i = 5;
        }
        if (snapshot.value != [NSNull null]){
            NSString *latitudestring = snapshot.value[@"latitude"];
            NSString *longitudestring = snapshot.value[@"longitude"];
        long latitude = [latitudestring longLongValue];
        long longitude = [longitudestring longLongValue];

        NSLog(@"latitude: %li and longitude: %li", latitude, longitude);

        CLLocationCoordinate2D position = CLLocationCoordinate2DMake(latitude, longitude);
        GMSMarker *marker = [GMSMarker markerWithPosition:position];
        marker.map = mapview;
        marker.title = (@"%@", snapshot.value[@"nome"]);
        marker.snippet = (@"%@", snapshot.value[@"endereco"]);
        }
    }
     ];


}

Sorry if the code it's kinda messy.

This error message appears: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString objectForKeyedSubscript:]

And the google maps markers aren't created at all. Any insight on this?

  • 2
    One object you think is a `NSDictionary` is in fact a `NSString`. Use breakpoint to know which line exactly is causing the issue. – Larme Sep 02 '16 at 16:16
  • can you post a snippet of your Firebase structure? As text please, no images. That may provide insight into the error. – Jay Sep 02 '16 at 17:13
  • It's more or less a list of places, each one with latitude, longitude, name (nome) and address (endereco). So 'places' is divided into 'place 1', 'place 2' etc. And each of these places has what I said. It's just that. I'm not sure if it's clear enough, but I think you got my point – user32367 Sep 03 '16 at 02:29
  • The error is explicit. It's a well known one. We can't help you if you don't give us the REAL structure of `snapshot.value` or help us to point out which line EXACTLY is causing the issue (using breakpoint for instance, or `NSLog()`). – Larme Sep 04 '16 at 17:15

1 Answers1

0

I found the answer just by changing FEEventTypeChildAdded to FEEventTypeValue. I can't really explain the reasoning, but at least it works.