在我的应用程序中,我已经完成了JSON解析,并且我以字典的形式获得了坐标,我想使用坐标angd在地图中绘制它,
我用过这个
SBJsonParser *jsonParser = [SBJsonParser new];
NSArray *jsonData = (NSArray *) [jsonParser objectWithString:outputData error:nil];
for(int i=0;i<[jsonData count];i++)
{
NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i];
Nslog(@"%@",dict);
double la=[[dict objectForKey:@"latitude"] doubleValue];
double lo=[[dict objectForKey:@"longitude"] doubleValue];
CLLocation * loca=[[CLLocation alloc]initWithLatitude:la longitude:lo];
CLLocationCoordinate2D coordi=loca.coordinate;
marker=[GMSMarker markerWithPosition:coordi];
marker.snippet = @"Hello World";
marker.animated = YES;
marker.map = mapView;
}
打印为
[{"driver_id":"Tn1234sunil@gmail.com","username":"sunil","latitude":"0.000000000000000",
"longitude":"0.000000000000000"},
{"driver_id":"ma12marii@yahoo.com","username":"mari","latitude":"13.040720500000000",
"longitude":"80.243139600000000"}, {"driver_id":"45sabala@gmail.com","username":"balaji","latitude":"0.000000000000000",
"longitude":"0.000000000000000"}
然后,在我的日志中,它将打印为
2014-01-04 10:55:48.121 MyTaxi[608:12e03] latitude : 0.000000
2014-01-04 10:55:48.121 MyTaxi[608:12e03] longitude : 0.000000
2014-01-04 10:55:48.122 MyTaxi[608:12e03] latitude : 13.040721
2014-01-04 10:55:48.122 MyTaxi[608:12e03] longitude : 80.243140
2014-01-04 10:55:48.122 MyTaxi[608:12e03] latitude : 0.000000
2014-01-04 10:55:48.123 MyTaxi[608:12e03] longitude : 0.000000
但是,这不能正常工作
Does any body have an idea how to plot these points to the google maps
答案 0 :(得分:4)
试试这个可能会有帮助,只需为你的计数创建一个for循环,增加它......
NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i];
double la=[[dict valueForKey:@"latitude"] doubleValue];
double lo=[[dict valueForKey:@"longitude"] doubleValue];
NSMutableArray * latArray=[[NSMutableArray alloc]init];
NSMutableArray * longArray=[[NSMutableArray alloc]init];
[latArray addObject:[NSNumber numberWithDouble:la]];
[longArray addObject:[NSNumber numberWithDouble:lo]];
CLLocation * loca=[[CLLocation alloc]initWithLatitude:[[latArray objectAtIndex:i]doubleValue] longitude:[[longArray objectAtIndex:i]doubleValue]];
CLLocationCoordinate2D coordi=loca.coordinate;
GMSMarker *marker= [[GMSMarker alloc] init];
marker=[GMSMarker markerWithPosition:coordi];
marker.position = CLLocationCoordinate2DMake([[latArray objectAtIndex:i]doubleValue], [[longArray objectAtIndex:i]doubleValue]);
marker.snippet = @"Hello World";
marker.animated = YES;
marker.map = mapView;
答案 1 :(得分:1)
我认为,您必须分配标记for for循环, 现在你只创建一个标记,
for(int i=0;i<[jsonData count];i++)
{
NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i];
double la=[dict valueForKey:@"latitude" doubleValue];
double lo=[dict valueForKey:@"longitude" doubleValue];
CLLocation * loca=[[CLLocation alloc]initWithLatitude:la longitude:lo];
CLLocationCoordinate2D coordi=loca.coordinate;
GMSMarker *marker= [[GMSMarker alloc] init];
marker=[GMSMarker markerWithPosition:coordi];
marker.snippet = @"Hello World";
marker.animated = YES;
marker.map = mapView;
.....
}