objective c - ALAssetPropertyLocation not working on any iOS 4.0+ on 3gs iPhones but working perfectly on iPhone4 -
i've got app location services enabled (from settings etc), , i'm reading photos device using alassetslibrary.
it works on iphone4 ios 4.2.1, same code , same assets dont work on 3gs ios (from 4.0 4.2.1).
the problem retrieves invalid cllocation on 3gs.
even on same picture (copied across both devices) on iphone4 returns valid cllocation, on 3gs returns invalid! picture image it's valid on both devices, cllocation invalid. dont have crashes , code doesnt step invalid blocks, works fine apart invalid cllocation data.
output of same asset , same code , same ios version (4.2.1):
iphone4: <+51.23816667, -0.57700000> +/- 0.00m (speed -1.00 mps / course -1.00) @ 19/02/2011 01:59:28 greenwich mean time
3gs: < nan, nan > +/- 0.00m (speed -1.00 mps / course -1.00) @ 2011-02-19 01:20:35 +0000
(note date on invalid location current time)
im getting cllocation this:
cllocation* location = [asset valueforproperty:alassetpropertylocation]; cllocationcoordinate2d coord = [location coordinate]; if ( !cllocationcoordinate2disvalid(coord) ) return;
the alassetslibrary code called in viewcontroller didload looks (totally standard):
alassetslibrary* library = [[alassetslibrary alloc] init]; void (^assetenumerator)(struct alasset *, nsuinteger, bool *) = ^(alasset *result, nsuinteger index, bool *stop) { if(result != null) { [self myfunction:result withindex:index]; } }; void (^assetgroupenumerator)(struct alassetsgroup *, bool *) = ^(alassetsgroup *group, bool *stop) { if(group != nil) { numberofassets = [group numberofassets]; [group enumerateassetsusingblock:assetenumerator]; } }; [library enumerategroupswithtypes:alassetsgroupall usingblock:assetgroupenumerator failureblock: ^(nserror *error) { nslog(@"oh no!"); }];
one last thing, on native photo app pictures shown in correct location on 3gs, must have data somewhere, doesnt read somehow!
i'm not entirely sure it's device (3gs) problem, never is...
in ios 4.0 , higher, can try using operate on alasset , retrieve location data (and more) photo asset retrieved either enumerating or using assetforurl
:
alassetrepresentation *representation = [asset defaultrepresentation]; nsdictionary *metadata = [representation metadata]; nsdictionary *gpsdict = [metadata objectforkey:@"{gps}"]; nsnumber *latitudenumber = [gpsdict objectforkey:@"latitude"]; nsstring *latituderef = [gpsdict objectforkey:@"latituderef"]; nsnumber *longitudenumber = [gpsdict objectforkey:@"longitude"]; nsstring *longituderef = [gpsdict objectforkey:@"longituderef"];
the latitude , longitude refs directions need translate positive (n, e) , negative (s, w). can use of information build simple cllocation. if need more, log or use debugger @ gpsdict (or metadata) , see keys use.
keep in mind data not there (photos taken in airplane mode) sure check values.
Comments
Post a Comment