如何在IOS中的地图中添加Pin和注释?
如何在ios中的地图中添加Pin和注释?如何在IOS中的地图中添加Pin和注释?,ios,objective-c,json,Ios,Objective C,Json,如何在ios中的地图中添加Pin和注释?#导入 #import <MapKit/MapKit.h> @property (strong, nonatomic) IBOutlet MKMapView *mapvie; //insert the one map view @属性(强,非原子)IBMMapView*mapvie//插入一个地图视图 在.m文件中 NSMutableArray *allocations=[[NSMutableArray alloc]init];
#导入
#import <MapKit/MapKit.h>
@property (strong, nonatomic) IBOutlet MKMapView *mapvie; //insert the one map view
@属性(强,非原子)IBMMapView*mapvie//插入一个地图视图
在.m文件中
NSMutableArray *allocations=[[NSMutableArray alloc]init];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.cbapcertprep.com/service/index.php?/Download_vehicletrack/DownloadTrackData/35170"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSArray *largeArray= [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];
NSArray *smallArray = [largeArray subarrayWithRange:NSMakeRange(0, 20)]; //this is range for what the result u need
for (int i=0; i<[smallArray count]; i++) {
CLLocationCoordinate2D annotationCoord;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationCoord.latitude = [[[smallArray objectAtIndex:i]objectForKey:@"latitude"]doubleValue ];
annotationCoord.longitude = [[[smallArray objectAtIndex:i]objectForKey:@"longitude"] doubleValue];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [[smallArray objectAtIndex:i]objectForKey:@"address"];
[allocations addObject:annotationPoint];
MKCoordinateRegion myRegion;
MKCoordinateSpan span;
span.latitudeDelta=THE_SPAN;
span.longitudeDelta=THE_SPAN;
myRegion.center=annotationCoord;
myRegion.span=span;
[self.mapvie setRegion:myRegion animated:YES];
}
[self.mapvie addAnnotations:allocations];
NSMutableArray*分配=[[NSMutableArray alloc]init];
NSMutableURLRequest*请求=[NSMutableUrlRequestRequestWithURL:[NSURL URLWithString:@]http://www.cbapcertprep.com/service/index.php?/Download_vehicletrack/DownloadTrackData/35170"]];
[请求设置HttpMethod:@“获取”];
[request setValue:@“application/json;charset=UTF-8”forHTTPHeaderField:@“content type”];
n错误*错误;
NSURLResponse*响应;
NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&响应错误:&错误];
NSArray*largeArray=[NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableContainers错误:&err];
NSArray*smallArray=[largeArray subraywithrange:NSMakeRange(0,20)]//这是你需要的结果的范围
对于(int i=0;i@Anbu.Karthik在该文件中,我尝试了它,但映射区域将自动更改。您的输出包含总计2643个索引,现在您需要显示的结果mapvie@Anbu.Karthik使用该日志,lat在地图上放置管脚?是的,我知道你的点,但是你的url显示2643值,你需要在你的url中显示2643管脚点map@Anbu.Karthik只有f前20分