原生地図
5361 ワード
オリジナルマップ:
(1)地図と測位機能を使用する場合、iOS開発では、この2つの機能を追加するには、2つのフレームワークに基づいて開発する必要があります.
(2)2つの人気専門用語
(3)CoreLocationフレームワーク使用前提:
(4)iOS 8以降、位置決めを要求する場合はinfoが必要です.plistファイルにN n s L o c t ionAlwaysUsageDescription(常に位置決め、バックグラウンドでも位置決め可能)、N s L o c t ionWhenInUseUsageDescription(使用時に位置決め)のフィールドを追加します.
(5)CLLocationManagerの一般的な操作
(5)地図MKMapView
(6)ピン:MKoserLocationは実はピンモデルで、以下の属性を含む
新しいピンモデルクラス
ピンのカスタマイズ方法
地図の中心点の位置を設定する
地図の表示領域を設定する
(1)地図と測位機能を使用する場合、iOS開発では、この2つの機能を追加するには、2つのフレームワークに基づいて開発する必要があります.
a、Map Kit: ;
b、Core Location: ;
(2)2つの人気専門用語
a、LBS:location Based Service
b、SoLoMo:Social Local Mobile( )
c、social( )、local( )、mobile( )。
(3)CoreLocationフレームワーク使用前提:
a、 :CoreLocation.framwork
b、 #import
c、CoreLocation CL;
d、CoreLocation CLLocationManager
(4)iOS 8以降、位置決めを要求する場合はinfoが必要です.plistファイルにN n s L o c t ionAlwaysUsageDescription(常に位置決め、バックグラウンドでも位置決め可能)、N s L o c t ionWhenInUseUsageDescription(使用時に位置決め)のフィールドを追加します.
(5)CLLocationManagerの一般的な操作
a、
- (void)startUpdatingLocation;
b、
- (void) stopUpdatingLocation;
c、 startUpdatingLocation , , :
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
locations CLLocation
CLLocation , 、 。
d、 :
@property(readonly, nonatomic) CLLocationCoordinate2D coordinate;
e、 :
@property(readonly, nonatomic) CLLocationDistance altitude;
, ( 0.0° ~ 359.9°,0.0° )
@property(readonly, nonatomic) CLLocationDirection course;
( m/s)
@property(readonly, nonatomic) CLLocationSpeed speed;
@property(assign, nonatomic) CLLocationDistance distanceFilter;
( )
@property(assign, nonatomic) CLLocationAccuracy desiredAccuracy;
CLLocationCoordinate2D , :
typedef struct {
CLLocationDegrees latitude; //
CLLocationDegrees longitude; //
} CLLocationCoordinate2D;
CLLocationCoordinate2DMake CLLocationCoordinate2D
(5)地図MKMapView
MKMaPView MapKit
MKMapView userTrackingMode
MKUserTrackingModeNone :
MKUserTrackingModeFollow :
MKUserTrackingModeFollowWithHeading : ,
MKMapView mapViewType
MKMapTypeStandard :
MKMapTypeSatellite :
MKMapTypeHybrid :
MKMapView ,
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation;
, ; , (userLocation ) 。
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
(6)ピン:MKoserLocationは実はピンモデルで、以下の属性を含む
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
- (void)addAnnotation:(id )annotation;
- (void)addAnnotations:(NSArray *)annotations;
- (void)removeAnnotation:(id )annotation;
- (void)removeAnnotations:(NSArray *)annotations;
(id )annotation ? : , 、 、 。
新しいピンモデルクラス
#import
@interface MyAnnotation : NSObject
/** */
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
/** */
@property (nonatomic, copy) NSString *title;
/** */
@property (nonatomic, copy) NSString *subtitle;
@end
MyAnnotation *anno = [[MyAnnotation alloc] init];
anno.title = @“123”;
anno.subtitle = @“456”;
anno.coordinate = CLLocationCoordinate2DMake(40, 116);
[self.mapView addAnnotation:anno];
ピンのカスタマイズ方法
MKMapView , , 。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation;
(id )annotation 。
: nil, , , , , , , (id )annotation
MKAnnotationView
MKAnnotationView
@property (nonatomic, strong) id annotation;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic) BOOL canShowCallout;
@property (strong, nonatomic) UIView *rightCalloutAccessoryView;
@property (strong, nonatomic) UIView *leftCalloutAccessoryView;
MKPinAnnotationView MKAnnotationView
@property (nonatomic) BOOL animatesDrop;
@property (readonly, nonatomic) CLLocation *location;
MKMapView ,
地図の中心点の位置を設定する
@property (nonatomic) CLLocationCoordinate2D centerCoordinate;
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated;
地図の表示領域を設定する
@property (nonatomic) MKCoordinateRegion region;
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated;
MKCoordinateRegion ,
typedef struct {
CLLocationCoordinate2D center; //
MKCoordinateSpan span; //
} MKCoordinateRegion;
MKCoordinateSpan
typedef struct {
CLLocationDegrees latitudeDelta; //
CLLocationDegrees longitudeDelta; //
} MKCoordinateSpan