Thursday 19 December 2013

Gps With Array in iphone


GpsViewController.h


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

@interface GpsViewController : UIViewController

@property (nonatomic,retain) IBOutlet MKMapView *mapView;
@property (nonatomic,retain) IBOutlet UISegmentedControl *sgmnt;

-(IBAction)segmentSelect:(id)sender;
@end

GpsViewController.m


#import "GpsViewController.h"
#import "MapStruct.h"
@synthesize mapView,
            sgmnt;
-(IBAction)segmentSelect:(id)sender
{
    if (sgmnt.selectedSegmentIndex==0) {
        [mapView setMapType:MKMapTypeStandard];
    }
    else if (sgmnt.selectedSegmentIndex==1) {
        [mapView setMapType:MKMapTypeSatellite];
    }
    else {
        [mapView setMapType:MKMapTypeHybrid];
    }

}       
- (void)viewDidLoad
{
    [super viewDidLoad];
   
    mapView.showsUserLocation=YES;
    [self setMap:22.3000:70.7800:@"Rajkot":@"The City of Saurastra"];
    [self setMap: 22.4700:70.0700:@"jamnagar":@"The City of Saurastra"];
   [self setMap:21.5200:70.4700:@"junagadh":@"The City of Saurastra"];
            // Do any additional setup after loading the view, typically from a nib.
}

-(void)setMap:(CLLocationDegrees)lati :(CLLocationDegrees)longi :(NSString *)tit :(NSString *)subtit
{
   
    MKCoordinateRegion region;
    region.center.latitude = lati;
    region.center.longitude = longi;
    region.span.longitudeDelta =  2.8f;
    region.span.latitudeDelta =  1.5f;
   
    [mapView setRegion:region animated:YES];
   
    MapStruct *ms=[[MapStruct alloc]init];
    ms.title=tit;
    ms.subtitle=subtit;
    ms.coordinate=region.center;
   
    [mapView addAnnotation:(id)ms];
   
    [mapView selectAnnotation:(id)ms animated:YES];
   
}

No comments:

Post a Comment

Comment