如何从ios中的dictionay中绘制谷歌地图中的标记? [英] How to plot the markers in google maps from a dictionay in ios?
本文介绍了如何从ios中的dictionay中绘制谷歌地图中的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我完成了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,纬度:0.000000000000000,
经度: 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}
$ b然后,在我的日志中,它被打印为2014-01-04 10:55:48.121 MyTaxi [608:12e03]纬度:0.000000
2014-01-04 10:55:48.121 MyTaxi [608:12e03]经度:0.000000
2014-01-04 10:55:48.122 MyTaxi [608:12e03]纬度:13.040721
2014-01-04 10:55:48.122 MyTaxi [608:12e03]经度:80.243140
2014- 01-04 10:55:48.122 MyTaxi [608:12e03]纬度:0.000000
2014-01-04 10:55:48.123 MyTaxi [608:12e03]经度:0.000000
$ c
但是,这不起作用正常
任何机构都有一个想法如何将这些点绘制到谷歌地图上
解决方案这个可能有帮助,只需要为你的计数创建一个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;
In my app, I have done JSON parsing and I got the coordinates in the form of a dictionary, I want to use the coordinates angd plot it in the map,
I have using thisSBJsonParser *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; }
it is printed as
[{"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"}
Then, In my log, it is getting printed as
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
But, this doesnt works properly
Does any body have an idea how to plot these points to the google maps
解决方案try this one this might be helpful just create a for loop to your count ,increment it ...
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;
这篇关于如何从ios中的dictionay中绘制谷歌地图中的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文