javaGeek
javaGeek

Reputation: 314

Map View Viewing Issues

I have my iPhone application that loads a map view, my problem is that it loads the map view zeroed in on one single map pin, I want it to load in a more holistic view that shows the whole map of the United States right when the app is launched. Is there a way to execute this? Here is my code:

ViewController.h

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

@interface ViewController : UIViewController
{
MKMapView *mapView;
}

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

-(IBAction)SetMap:(id)sender;

-(IBAction)GetLocation:(id)sender;

-(IBAction)Directions:(id)sender;

@end

ViewController.m

#import "ViewController.h"
#import "MapPin.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize mapView;

- (void)viewDidLoad
{
[super viewDidLoad];

//Moss Preserve coordinates
MKCoordinateRegion MossPreserveRegion = { {0.0, 0.0}, {0.0, 0.0}};
MossPreserveRegion.center.latitude = 33.3816566;
MossPreserveRegion.center.longitude = -86.8415451;
MossPreserveRegion.span.longitudeDelta = 0.01f;
MossPreserveRegion.span.latitudeDelta = 0.01f;
[mapView setRegion:MossPreserveRegion animated:YES];

//Moss Preserve annotation and map pin
MapPin *MossPreserveAnnotation = [[MapPin alloc] init];
MossPreserveAnnotation.title = @"Moss Rock Preserve Boulder Fields";
MossPreserveAnnotation.subtitle = @"Preserve Pkwy, Hoover, AL";
MossPreserveAnnotation.coordinate = MossPreserveRegion.center;
[mapView addAnnotation:MossPreserveAnnotation];

//Horse Pens 40 coordinates
MKCoordinateRegion HorsePenRegion = { {0.0, 0.0}, {0.0, 0.0}};
HorsePenRegion.center.latitude = 33.9207535;
HorsePenRegion.center.longitude = -86.3089447;
HorsePenRegion.span.longitudeDelta = 0.01f;
HorsePenRegion.span.latitudeDelta = 0.01f;
[mapView setRegion:HorsePenRegion animated:YES];

//Horse Pens 40 annotation and map pin
MapPin *HorsePenAnnotation = [[MapPin alloc] init];
HorsePenAnnotation.title = @"Horse Pens 40";
HorsePenAnnotation.subtitle = @"Steele, AL ";
HorsePenAnnotation.coordinate = HorsePenRegion.center;
[mapView addAnnotation:HorsePenAnnotation];
}

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

-(IBAction)SetMap:(id)sender;
{
switch (((UISegmentedControl *) sender).selectedSegmentIndex)
{
    case 0:
        mapView.mapType = MKMapTypeStandard;
        break;
    case 1:
        mapView.mapType = MKMapTypeSatellite;
        break;
    case 2:
        mapView.mapType = MKMapTypeHybrid;
        break;

    default:
        break;
}
}

-(IBAction)GetLocation:(id)sender;
{
mapView.showsUserLocation = YES;
}

-(IBAction)Directions:(id)sender;
{
NSString *urlString = @"http://maps.apple.com/maps?daddr=33.3816566,-86.8415451";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}

@end

MapPin.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapPin : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;

NSString *title;
NSString *subtitle;
}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;

@end

MapPin.m

#import "MapPin.h"

@implementation MapPin

@synthesize coordinate, title, subtitle;

@end

Thank you for any advice

Upvotes: 0

Views: 104

Answers (1)

Bikram Thapa
Bikram Thapa

Reputation: 1339

You need to set the zoom level of an MKMapView. Better look at this: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/

Upvotes: 1

Related Questions