gpt4 book ai didi

ios - map View 查看问题

转载 作者:行者123 更新时间:2023-11-29 02:57:46 27 4
gpt4 key购买 nike

我的 iPhone 应用程序加载了 map View ,我的问题是它加载的 map View 归零在一个 map 图钉上,我希望它加载一个显示整个美国 map 的更全面的 View 就在应用程序启动时。有没有办法执行这个?这是我的代码:

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

谢谢你的建议

最佳答案

您需要设置 MKMapView 的缩放级别。最好看看这个: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/

关于ios - map View 查看问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23692901/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com