map pin multiple

#import <MapKit/MapKit.h>

MKMapViewDelegate,CLLocationManagerDelegate

-(void)mappin

{

    NSLog(@”%lu”,(unsigned long)app.arr_main_data.count);

    NSLog(@”%lu”,(unsigned long)[[app.arr_main_data valueForKey:@”lat”]count ]);

    CLLocationCoordinate2D loc;

    for (int x=0; x<app.arr_main_data.count; x++)

    {

        loc.latitude=[[[app.arr_main_data valueForKey:@”lat”] objectAtIndex:x]doubleValue];

        loc.longitude=[[[app.arr_main_data valueForKey:@”long”] objectAtIndex:x]doubleValue];

        

        NSLog(@”%f”,loc.latitude);

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

        

        

        

        myano.coordinate=loc;

        // NSString *str_ttl=[arr_get_title objectAtIndex:x];

        NSString *strr_cityname = [[app.arr_nme objectAtIndex:x] stringByReplacingOccurrencesOfString:@”Testing –” withString:@””];

        

        myano.title=strr_cityname;

        

        

        MKCoordinateRegion adjustedRegion = [map regionThatFits:MKCoordinateRegionMakeWithDistance(loc, 1000, 1000)];

        adjustedRegion.span.longitudeDelta  = 0.02;

        adjustedRegion.span.latitudeDelta  = 0.02;

        

        [map setRegion:adjustedRegion animated:YES];

        

        [map addAnnotation:myano];

        map.centerCoordinate=loc;

        

        

        

    }

    

    //  [mymap_all addAnnotation:myano];

    //   mymap_all.centerCoordinate=loc;

    [map showsUserLocation];

    

}

– (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

    // if its the user location, just return nil

    if ([annotation isKindOfClass:[MKUserLocation class]])

        return nil;

    

    // Try to dequeue an existing pin view first

    static NSString *AnnotationIdentifier =@”AnnotationIdentifier”;

    MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];

    pinView.pinColor = MKPinAnnotationColorPurple;

    pinView.animatesDrop = YES;

    pinView.canShowCallout = YES;

    

    // UIButton *detailbtn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    //NSInteger annotationValue = annotation

    

    [rightButton addTarget:self action:@selector(map_tag_click:) forControlEvents:UIControlEventTouchUpInside];

    rightButton.tag=lol;

    NSLog(@”%ld”,(long)rightButton.tag);

    

    //[rightButton addTarget:self action:@selector(showDV:) forControlEvents:UIControlEventTouchUpInside];

    pinView.rightCalloutAccessoryView = rightButton;

    

    

    

    return pinView;

}

-(IBAction)map_tag_click:(UIButton *)sender

{

    /* NSLog(@”%ld”,(long)sender.tag);

     NSLog(@”%@”,[arr_get_title objectAtIndex:sender.tag]);

     NSString *strrr=[arr_get_slug objectAtIndex:sender.tag];

     

     NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@”http://corporateletting.com/?json=get_post&post_type=ad_listing&slug=%@“,[strrr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

     NSLog(@”%@”,url);

     NSURLRequest *req =[[NSURLRequest alloc]initWithURL:url];

     NSError *err;

     NSURLResponse *res;

     NSData *d1 =[NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err];

     NSDictionary *dict =[NSJSONSerialization JSONObjectWithData:d1 options:NSJSONReadingAllowFragments error:&err];

     app.bthview_Arry_Prti=[dict valueForKey:@”post”];

     NSLog(@”%@”,app.bthview_Arry_Prti);

     PropertyDetailView *pdv =[self.storyboard instantiateViewControllerWithIdentifier:@”PropertyDetailView”];

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

     */

}

-(void)showdetail:(NSInteger)number

{

    NSLog(@”%ld”,(long)number);

    NSLog(@”%@”,[app.arr_nme objectAtIndex:number]);

    NSString *strrr=[app.arr_nme objectAtIndex:number];

    NSString *str_id=[[app.arr_main_data valueForKey:@”id”]  objectAtIndex:number];

    NSLog(@”%@”,strrr);

    NSLog(@”%@”,str_id);

    app.main_tnt=10;

    

//    NSString *urlstring = [NSString stringWithFormat:@”http://corporateletting.com/?json=get_post&post_type=ad_listing&slug=%@“,[strrr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    

    NSString *urlstring=[NSString stringWithFormat:@”http://webapi.bonappetitcard.com/api/api.php?method=Get_Restaurants&restaurant_id=%@&#8221;,[str_id stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

//

    NSLog(@”%@”,urlstring);

    

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    

    

    manager.requestSerializer = [AFJSONRequestSerializer serializer];

    manager.responseSerializer = [AFJSONResponseSerializer serializer];

    manager.responseSerializer.acceptableContentTypes=[manager.responseSerializer.acceptableContentTypes setByAddingObject:@”text/html”];

    

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    

    [manager GET:urlstring parameters:nil

     

     

         success:^(AFHTTPRequestOperation *operation, id responseObject)

     

     {

         [MBProgressHUD hideHUDForView:self.view animated:YES];

         

         NSLog(@”JSON: %@”, responseObject);

         

         NSDictionary   *dict_chk = (NSDictionary *) responseObject;

         

         NSLog(@”dict %@”, dict_chk);

         if ([[dict_chk valueForKey:@”status”] isEqualToString:@”Success”])

         {

          //   NSLog(@”%@”,[[dict_chk valueForKey:@”restaurant_list”] objectAtIndex:0]);

             NSArray *arr12=[[dict_chk valueForKey:@”restaurant_list”]objectAtIndex:0];

             

             app.arr_al1_htl_dtl=[(NSMutableArray *)arr12 objectAtIndex:0];

             NSLog(@”%@”,app.arr_al1_htl_dtl);

           //  NSLog(@”%@”,[app.arr_al1_htl_dtl objectAtIndex:0]);

             view_particular_htl_details *vphd=[self.storyboard instantiateViewControllerWithIdentifier:@”view_particular_htl_details”];

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

         }

         else

         {

             

         }

         

//         app.bthview_Arry_Prti=[dict_chk valueForKey:@”post”];

//         NSLog(@”%@”,app.bthview_Arry_Prti);

//         PropertyDetailView *pdv =[self.storyboard instantiateViewControllerWithIdentifier:@”PropertyDetailView”];

//         [self.navigationController pushViewController:pdv animated:YES];

         

         

         

     }

         failure:^(AFHTTPRequestOperation *operation, NSError *error)

     {

         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”Error Retrieving Weather”

                                                             message:[error localizedDescription]

                                                            delegate:nil

                                                   cancelButtonTitle:@”Ok”

                                                   otherButtonTitles:nil];

         [alertView show];

         

         

         NSLog(@”Error: %@”, alertView);

     }];

    

    

    

    

    

    

    

    

    //     NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@”http://corporateletting.com/?json=get_post&post_type=ad_listing&slug=%@“,[strrr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

    //     NSLog(@”%@”,url);

    //     NSURLRequest *req =[[NSURLRequest alloc]initWithURL:url];

    //     NSError *err;

    //     NSURLResponse *res;

    //     NSData *d1 =[NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err];

    //     NSDictionary *dict =[NSJSONSerialization JSONObjectWithData:d1 options:NSJSONReadingAllowFragments error:&err];

    //     app.bthview_Arry_Prti=[dict valueForKey:@”post”];

    //     NSLog(@”%@”,app.bthview_Arry_Prti);

    //     PropertyDetailView *pdv =[self.storyboard instantiateViewControllerWithIdentifier:@”PropertyDetailView”];

    //     [self.navigationController pushViewController:pdv animated:YES];

    

}

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

    id <MKAnnotation> annotation = [view annotation];

    if ([annotation isKindOfClass:[MKPointAnnotation class]])

    {

        NSLog(@”calloutAccessoryControlTapped: annotation = %@”, view.annotation);

    }

    

    

    

    CLLocationCoordinate2D cd=  [view.annotation coordinate];

    NSNumber *lat = [NSNumber numberWithDouble:cd.latitude];

    [self showdetail:([[app.arr_main_data valueForKey:@”lat”] indexOfObject:[lat stringValue]])];

    

    

    // for (NSString *s  in arr_get_lati) {

    //     NSLog(s);

    // }

    //   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@”%d”,[arr_get_lati indexOfObject:[lat stringValue]]] message:@”Click Cancel to Go Back” delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles:@”OK”, nil];

    //[alertView show];

    

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s