我无法在地图上显示加载来自parse.com的坐标,标题和副标题的图钉。 这是我的代码。有什么逻辑错误吗?我只得到数据库显示的第三行,而不是我在parse.com上的所有五行。
for(int i = 0; i<objects.count; i++)
{
int raknare = 1;
raknare++;
PFObject *tempObject = [kundUppgifter objectAtIndex:raknare];
PFGeoPoint *geoPoint = [tempObject objectForKey:@"CLAT"];
PFGeoPoint *geoPoint2 = (PFGeoPoint *)geoPoint;
NSString *cname = @"CNAME";
NSString *ctown = @"CTOWN";
kundUppgifter = [[NSArray alloc] initWithArray:objects];
objects = [NSArray arrayWithObjects:cname,ctown,geoPoint,nil];
NSMutableArray * locations = [[NSMutableArray alloc]init];
Annotation * myAnn;
myAnn = [[Annotation alloc]init];
CLLocationCoordinate2D location;
double longitude;
double latitude;
latitude = geoPoint2.latitude;
longitude = geoPoint2.longitude;
location.latitude = latitude;
location.longitude = longitude;
geoPoint.latitude = latitude;
geoPoint.longitude = longitude;
myAnn.coordinate = location;
myAnn.title = [tempObject objectForKey:@"CNAME"];
myAnn.subtitle = [tempObject objectForKey:@"CTOWN"];
[locations addObject:myAnn];
[self.myMapView addAnnotations:locations];
NSLog(@"geopoint is a pfobject with latitude %f, and longitude %f kundnamn %@,stad %@,", latitude, longitude, cname, ctown);
NSLog(@"%@", cname);
NSLog(@"%@", objects);
}
}
}];
如果你能提供帮助,我们很高兴!
答案 0 :(得分:1)
for(int i = 0; i<objects.count; i++)
{
int raknare = 1;
raknare++;
PFObject *tempObject = [kundUppgifter objectAtIndex:raknare];
}
循环中的这段代码会在循环的每次迭代中使raknare == 2。你想使用你设置的i变量从-objectAtIndex中提取:像这样
for(int i = 0; i<objects.count; i++)
{
// This gives you a different object each iteration of the loop
PFObject *tempObject = [kundUppgifter objectAtIndex:i];
}