0

你好朋友,我在stackoverflow上上传了我最近几天的代码,但是我没有得到我想要的东西。不,我再次尝试这个,请尝试帮助我并解决我的问题。首先看代码。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

欢迎视图控制器.h

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>

@interface welcomemapViewController : UIViewController
@property (strong, nonatomic) UITextField *txt;
@end

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

欢迎视图控制器.m

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#import "welcomemapViewController.h"
#import <GoogleMaps/GoogleMaps.h>

#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define kLatestSearchURL [NSURL URLWithString: @"https://maps.googleapis.com/maps/api/place/textsearch/xml?query=Delhi&sensor=true&key=Your API key"]

@interface welcomemapViewController ()
@end


@implementation welcomemapViewController
{
    GMSMapView *gmap;
}

@synthesize txt;

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

- (void)viewDidLoad
{
    [super viewDidLoad];

     GMSCameraPosition *cam = [GMSCameraPosition cameraWithLatitude:30.7343000 longitude:76.7933000 zoom:12];
     gmap = [GMSMapView mapWithFrame:CGRectMake(0, 60, 320, 480) camera:cam];
     gmap.myLocationEnabled = YES;
     gmap.mapType = kGMSTypeHybrid;
     gmap.settings.myLocationButton = YES;
     gmap.settings.zoomGestures = YES;
     gmap.settings.tiltGestures = NO;
     gmap.settings.rotateGestures = YES;
     [self.view addSubview:gmap];

     GMSMarker *marker = [[GMSMarker alloc] init];
     marker.position = CLLocationCoordinate2DMake(30.751288, 76.780899);
     marker.title = @"Sector -16";
     marker.snippet = @"Chandigarh";
     marker.map = gmap;

     UIButton *button    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     button.frame        = CGRectMake(200, 65, 100, 40);
     [button setTitle:@"SEARCH" forState:UIControlStateNormal];
     [button addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:button];

     CGRect frame2 = CGRectMake(10, 68, 200, 30);
     txt =[[UITextField alloc]initWithFrame:frame2];
     txt.placeholder = @"Search";
     txt.userInteractionEnabled = YES;
     txt.keyboardType = UIKeyboardTypeAlphabet;
     [txt setBorderStyle:UITextBorderStyleRoundedRect];

     [self.view addSubview:txt];

     // Do any additional setup after loading the view from its nib.
}
-(IBAction)search:(id)sender
{
    NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=30.7343000,76.7933000&radius=500&types=food&name&sensor=true&key=AIzaSyCGeIN7gCxU8baq3e5eL0DU3_JHeWyKzic"];
    //Formulate the string as URL object.
    NSURL *googleRequestURL=[NSURL URLWithString:url];
    // Retrieve the results of the URL.
    dispatch_async(kBgQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    });
}
- (void)fetchedData:(NSData *)responseData {
    //parse out the json data
    NSString *data1 = [NSString stringWithUTF8String:[responseData bytes]];
    NSLog(@"Response data: %@", data1);
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    //The results from Google will be an array obtained from the NSDictionary object with the key "results".
    NSArray* responseResults = [json objectForKey:@"results"];

    NSLog(@"Locations are %@", responseResults);
}

- (void)didReceiveMemoryWarning
{
     [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

现在在“ NSLog(@"Locations are %@", responseResults); ”中,我正在获取我的值,我只是想以带有详细信息的指针的形式将这些值添加到地图上。所以请帮助我应该如何做。(请在代码的帮助下帮助我

4

1 回答 1

1

你可以通过使用 MKPointAnnotation 来做到这一点,然后在你的地图视图中添加这个 MKPointAnnotation

CLLocationCoordinate2D annotationCoord;

annotationCoord.latitude = @"your Latitude to point on map";
annotationCoord.longitude =  @"your Longitude to point on map";;

MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];

annotationPoint.coordinate = annotationCoord;
annotationPoint.title = @"your title";
annotationPoint.subtitle = @"your subtitle";

[YourmapView addAnnotation:annotationPoint];

于 2013-10-25T06:52:32.693 回答