我可以解析數據庫中的數據,但難於循環查看數據庫中的所有座標並將它們繪製在mapview上。有人可以請幫助。問題通過數據庫中的座標數組循環遍歷
-(void)scanDatabase{
UIDevice *device = [UIDevice currentDevice];
NSString *uid = [device uniqueIdentifier];
NSString *myUrl = [NSString stringWithFormat:@"http://address.php?uid=%@",uid];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: myUrl ]];
// to receive the returend value
NSString *serverOutput =[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSArray *components = [serverOutput componentsSeparatedByString:@"\n"];
for (NSString *line in components) {
NSArray *fields = [line componentsSeparatedByString:@"\t"];
[eventPoints addObjectsFromArray:fields];
int count = [fields count];
for(int i=0;i < count; i++) {
int myindex0 = i*count;
int myindex1 = (i*count)+1;
int myindex2 = (i*count)+2;
NSString *mytitle = [eventPoints objectAtIndex:myindex0];
NSNumber *myLat = [eventPoints objectAtIndex:myindex1];
NSNumber *myLon = [eventPoints objectAtIndex:myindex2];
CLLocationCoordinate2D loc;
loc.latitude = myLat.doubleValue;
loc.longitude = myLon.doubleValue;
customAnnotation *event = [[customAnnotation alloc] initWithCoordinate:loc];
event.title = mytitle;
MKPinAnnotationView *newAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:event reuseIdentifier:@"simpleAnnotation"];
newAnnotationPin.pinColor = MKPinAnnotationColorRed;
[map addAnnotation:event];
}
}
}
謝謝沃爾克,那就是我一直在尋找的.. ifelse聲明工作。 – Cocell