Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode Xode4如何将lat和long数据从flickr传递到mapview xib文件_Xcode_Xcode4_Mkmapview - Fatal编程技术网

Xcode Xode4如何将lat和long数据从flickr传递到mapview xib文件

Xcode Xode4如何将lat和long数据从flickr传递到mapview xib文件,xcode,xcode4,mkmapview,Xcode,Xcode4,Mkmapview,这里的xcode非常新。我能够获取flickr数据,然后在单击较小的图像时显示较大的图像 从Flickr中,我还获得了经度和纬度数据 我希望能够显示带有每个图像的long和lat的地图,然后使用mapview将其显示在xib上 如何将数据从WebserviceEXVC.m传递到DVC.H和DVC.m?(我已经在xib上显示了较大的图像。我想用地图替换较大的图像。如何在地图视图中显示长图像和lat图像 WebServiceExampleVC.h // //

这里的xcode非常新。我能够获取flickr数据,然后在单击较小的图像时显示较大的图像

从Flickr中,我还获得了经度和纬度数据

我希望能够显示带有每个图像的long和lat的地图,然后使用mapview将其显示在xib上

如何将数据从WebserviceEXVC.m传递到DVC.H和DVC.m?(我已经在xib上显示了较大的图像。我想用地图替换较大的图像。如何在地图视图中显示长图像和lat图像

        WebServiceExampleVC.h





    //
    //  WebServiceExampleViewController.h
    //  WebServiceExample
    //
    //  Created by Computerlab on 7/22/12.
    //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    //

    #import <UIKit/UIKit.h>

    @interface WebServiceExampleViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{

        NSMutableArray* photoTitles;
        NSMutableArray* photoSmallImageData;
        NSMutableArray* photoURLsLargeImage;
        //latitude":48.886392, "longitude"
        NSMutableArray* photolongitude;
        NSMutableArray* photolatitude;


        NSMutableArray* photoURLsLargeData;

        NSURLConnection* connection;
        NSMutableData* receivedData;

    }    

    @property (nonatomic, strong) IBOutlet UITableView* myTableView;

    -(void)searchFlickrPhotos:(NSString*)text;

    @end



        WebServiceExampleVC.m





     //
        //  WebServiceExampleViewController.m
        //  WebServiceExample
        //
        //  Created by Computerlab on 7/22/12.
        //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
        //

        #import "WebServiceExampleViewController.h"
        #import "DVC.h"


        //NSString *const FlickrAPIKey = @"ac35247e7b67528944f322cceb05704b";
        //My Key
        NSString *const FlickrAPIKey = @"00af42177056c5b71bda9bd49938c1df";

        @interface WebServiceExampleViewController ()

        @end

        @implementation WebServiceExampleViewController
        @synthesize myTableView;


        -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
            static NSString* CellIdentifier = @"Cell";
            int row = indexPath.row;

            UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

            if(cell == nil){
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
                NSLog(@"%d - NEW CELL", row);
            }
            else {
                NSLog(@"%d - OLD CELL", row);
            }

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

            UILabel* x2 = cell.textLabel;
            CGRect r = x2.frame;
            r.size.height = 100;
            x2.frame = r;
            x2.text = [NSString stringWithFormat:@"%d", row];

            UILabel* detailText = cell.detailTextLabel;
           // detailText.text = [NSString stringWithFormat:@"%s", "title"];


            NSString* title = (NSString*) [photoTitles objectAtIndex:row];
            detailText.text = [NSString stringWithFormat:@"%@", title];
            NSString* lat = (NSString*) [photolatitude objectAtIndex:row];
            detailText.text = [NSString stringWithFormat:@"%@", lat];
            NSString* longi = (NSString*) [photolongitude objectAtIndex:row];
            detailText.text = [NSString stringWithFormat:@"Lat %@\r\n,Long %@\n\n,title %@\n\n", lat ,longi, title];
            //detailText.text =[NSString stringWithFormat:latitude];
            // detailText.text = [NSString stringWithFormat:@"%s", "Longitude"];
            UIImageView* imageView = cell.imageView;
            NSData* imageData = (NSData*) [photoSmallImageData objectAtIndex:row];
            imageView.image = [UIImage imageWithData:imageData];
            return cell;

        }


        - (void)connectionDidFinishLoading:(NSURLConnection *)connection{

            NSError* error;

            NSDictionary* results = [NSJSONSerialization JSONObjectWithData:receivedData
                                                                    options:kNilOptions
                                                                      error:&error];

            NSArray *photos = [[results objectForKey:@"photos"] objectForKey:@"photo"];

            for (NSDictionary *photo in photos)
            {
                NSString *title = [photo objectForKey:@"title"];
                [photoTitles addObject:(title.length > 0 ? title : @"Untitled")];
                NSLog(@"title: %@", title);

                NSString *latitude = [photo objectForKey:@"latitude"];
               [photolatitude addObject: [NSString stringWithFormat:@"%@", latitude]];
                //NSLog(@"photolatitude: %@", photolatitude);
                 NSLog(@"latitude: %@", latitude);

                NSString *longitude = [photo objectForKey:@"longitude"];
                [photolongitude addObject: [NSString stringWithFormat:@"%@", longitude]];
                //NSLog(@"photolongitude: %@",photolongitude);
                NSLog(@"longitude: %@",longitude);

                // Build the URL to where the image is stored (see the Flickr API)
                // In the format http://farmX.static.flickr.com/server/id/secret
                // Notice the "_s" which requests a "small" image 75 x 75 pixels
                NSString *photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_s.jpg", [photo objectForKey:@"farm"], [photo objectForKey:@"server"], [photo objectForKey:@"id"], [photo objectForKey:@"secret"]]; 
                NSLog(@"photoURLString: %@", photoURLString);
                [photoSmallImageData addObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoURLString]]];
                photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_m.jpg", [photo objectForKey:@"farm"], [photo objectForKey:@"server"], [photo objectForKey:@"id"], [photo objectForKey:@"secret"]];
                [photoURLsLargeImage addObject:[NSURL URLWithString:photoURLString]]; 
                NSLog(@"photoURLsLareImage: %@\n\n", photoURLString); 


                [photoURLsLargeData addObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoURLString]]];

                  //NSLog(@"photoURLsLargeData: %@\n\n", photoURLsLargeData);






            }

            NSLog(@"Size of dictionary: %d", photoSmallImageData.count);
            [myTableView reloadData];
        }


        -(void)searchFlickrPhotos:(NSString *)text
        {
            // Build the string to call the Flickr API
          /*  NSString *urlString =
            [NSString stringWithFormat:
             @"http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&per_page=50&format=json&nojsoncallback=1", FlickrAPIKey, text];
            */

            // Build the string to call the Flickr API
            NSString *urlString =
            [NSString stringWithFormat:
             @"http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&per_page=5&format=json&nojsoncallback=1&has_geo=1&extras=geo", FlickrAPIKey, text];


            NSLog(@"REQ SENT: %@", urlString);
            NSURL *url = [NSURL URLWithString:urlString];

            // Setup and start async download
            NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
            connection = [[NSURLConnection alloc] initWithRequest:request 
                                                         delegate:self];

        }


        -(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse *)response{
            [receivedData setData:nil];
        }

        -(void)connection:(NSURLConnection*)connection didReceiveData:(NSData *)data{
            [receivedData appendData:data];
        }



        -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
            return photoSmallImageData.count;
        }


        -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
            return 150.0f;
        }



        - (void)viewDidLoad
        {
            [super viewDidLoad];
            // Do any additional setup after loading the view, typically from a nib.
            photoTitles = [[NSMutableArray alloc] init];
            photoSmallImageData = [[NSMutableArray alloc] init];
            photoURLsLargeImage = [[NSMutableArray alloc] init];
            photoURLsLargeData = [[NSMutableArray alloc] init];
            photolongitude = [[NSMutableArray alloc] init];
            photolatitude = [[NSMutableArray alloc] init];

            receivedData = [[NSMutableData alloc] init];
            [self searchFlickrPhotos:@"cars"];

        }

        - (void)viewDidUnload
        {
            [super viewDidUnload];
            // Release any retained subviews of the main view.
        }

        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
        {
            return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
        }


        -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


        NSData* imageData = (NSData*) [photoURLsLargeData objectAtIndex:indexPath.row];
            [[NSUserDefaults standardUserDefaults] setObject:imageData
                                                      forKey:@"largeImage"];
            [[NSUserDefaults standardUserDefaults] synchronize];

            //[[NSUserDefaults standardUserDefaults] setObject:<#(id)#> forKey:<#(NSString *)#>]

            DVC* detailView = [[DVC alloc] initWithNibName:@"DVC"
                                                    bundle:nil];

            [self.navigationController pushViewController:detailView
                                                 animated:YES];

        }




        @end




        DVC.h





 /*****
    #import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>

    @interface mapiphoneViewController : UIViewController <MKMapViewDelegate>


    @property (strong, nonatomic) IBOutlet MKMapView* map;



    @end
    ****/

        //
        //  DVC.h
        //  WebServiceExample
        //
        //  Created by Computerlab on 7/29/12.
        //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
        //

        #import <UIKit/UIKit.h>

        @interface DVC : UIViewController

        @property (strong, nonatomic) IBOutlet UIImageView* myImageView;

        @end


        DVC.m



  //
    //  DVC.m
    //  WebServiceExample
    //
    //  Created by Computerlab on 7/29/12.
    //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    //

    #import "DVC.h"

    @interface DVC ()

    @end

    @implementation DVC
    @synthesize myImageView;

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.

        NSData* myData = [[NSUserDefaults standardUserDefaults] dataForKey:@"largeImage"];
        myImageView.image = [UIImage imageWithData:myData];


    }

    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

    @end




    ///Map stuff

/*****************************************************    
    @synthesize map;

    -(MKOverlayView*) mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay  {

        MKCircleView* circleView =[[MKCircleView alloc] initWithOverlay:overlay];
        circleView.strokeColor = [UIColor blueColor];
        circleView.fillColor = [UIColor redColor];
        return circleView;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.

        float latitude = 40.0;
        float longitude  = -75.0;

        CLLocationCoordinate2D x;
        x.latitude = latitude;
        x.longitude = longitude;

        MKCoordinateSpan z;
        z.latitudeDelta = 0.15;
        z.longitudeDelta = 0.15;

        MKCoordinateRegion y;
        y.center = x;
        y.span = z;

        map.region = y;
        [map addOverlay:[MKCircle circleWithCenterCoordinate:x
                                                      radius:1000]];
    }


******/
webservice示例vc.h
//
//WebServiceExampleViewController.h
//WebService示例
//
//由Computerlab于2012年7月22日创建。
//版权所有(c)2012 uu MyCompanyName uuu。保留所有权利。
//
#进口
@接口WebService示例ViewController:UIViewController{
NSMutableArray*照片标题;
NSMutableArray*photoSmallImageData;
NSMutableArray*photoURLsLargeImage;
//纬度:48.886392,“经度”
NSMutableArray*光经;
NSMutableArray*光纬度;
NSMutableArray*photoURLsLargeData;
NSURLConnection*连接;
NSMutableData*接收数据;
}    
@属性(非原子,强)IBUITableView*myTableView;
-(作废)SearchFlickphotos:(NSString*)文本;
@结束
WebServiceExampleVC.m
//
//WebServiceExampleViewController.m
//WebService示例
//
//由Computerlab于2012年7月22日创建。
//版权所有(c)2012 uu MyCompanyName uuu。保留所有权利。
//
#导入“WebServiceExampleViewController.h”
#导入“DVC.h”
//NSString*const FlickrAPIKey=@“AC35247B67528944F322CCEB05704B”;
//我的钥匙
NSString*const FlickrAPIKey=@“00af42177056c5b71bda9bd49938c1df”;
@接口WebService示例ViewController()
@结束
@实现WebServiceExampleViewController
@综合myTableView;
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“Cell”;
int row=indexPath.row;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier];
NSLog(@“%d-新单元格”,第行);
}
否则{
NSLog(@“%d-旧单元格”,第行);
}
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
UILabel*x2=cell.textLabel;
CGRect r=x2.1帧;
r、 尺寸.高度=100;
x2.frame=r;
x2.text=[NSString stringWithFormat:@“%d”,第行];
UILabel*detailText=cell.detailTextLabel;
//detailText.text=[NSString stringWithFormat:@“%s”,“title”];
NSString*title=(NSString*)[photoTitles对象索引:行];
detailText.text=[NSString stringWithFormat:@“%@”,title];
NSString*lat=(NSString*)[photolatitude对象索引:行];
detailText.text=[NSString stringWithFormat:@“%@”,lat];
NSString*longi=(NSString*)[光经对象索引:行];
detailText.text=[NSString stringWithFormat:@“Lat%@\r\n,Long%@\n\n,title%@\n\n”,Lat,longi,title];
//detailText.text=[NSString stringWithFormat:latitude];
//detailText.text=[NSString stringWithFormat:@“%s”,“经度”];
UIImageView*imageView=cell.imageView;
NSData*imageData=(NSData*)[photoSmallImageData对象索引:行];
imageView.image=[UIImage imageWithData:imageData];
返回单元;
}
-(无效)连接IDFinishLoading:(NSURLConnection*)连接{
n错误*错误;
NSDictionary*results=[NSJSONSerialization JSONObjectWithData:receivedData
选项:针织品
错误:&错误];
NSArray*photos=[[results objectForKey:@“photos”]objectForKey:@“photo”];
用于(NSDictionary*照片中的照片)
{
NSString*title=[photo objectForKey:@“title]”;
[照片标题添加对象:(title.length>0?title:@“未命名”);
NSLog(@“标题:%@”,标题);
NSString*纬度=[photo objectForKey:@“纬度”];
[photolatitude添加对象:[NSString stringWithFormat:@“%@”,latitude]];
//NSLog(@“光纬度:%@”,光纬度);
NSLog(@“纬度:%@”,纬度);
NSString*经度=[photo objectForKey:@“经度”];
[照片经度添加对象:[NSString stringWithFormat:@“%@”,经度]];
//NSLog(@“光经:%@”,光经);
NSLog(@“经度:%@”,经度);
//构建存储图像的URL(请参阅Flickr API)
//格式http://farmX.static.flickr.com/server/id/secret
//请注意“_s”,它要求75 x 75像素的“小”图像
NSString*photoURLString=[NSString stringWithFormat:@”http://farm%@.static.flickr.com/%@/%@u%@_.jpg“,[photo objectForKey:@“farm”],[photo objectForKey:@“server”],[photo objectForKey:@“id”],[photo objectForKey:@“secret”];
NSLog(@“photoURLString:%@”,photoURLString);
[photoSmallImageData添加对象:[NSData DATA WITHCONTENTSOFURL:[NSURL URLWithString:photoURLString]];
photoURLString=[NSString stringWithFormat:@“http: