|
@@ -11,19 +11,8 @@
|
|
|
#import <Contacts/Contacts.h>
|
|
#import <Contacts/Contacts.h>
|
|
|
#import <ContactsUI/ContactsUI.h>
|
|
#import <ContactsUI/ContactsUI.h>
|
|
|
#import <MapKit/MapKit.h>
|
|
#import <MapKit/MapKit.h>
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-#pragma mark - Annotation
|
|
|
|
|
-
|
|
|
|
|
-@interface AMMapAnnotaion : MKPointAnnotation
|
|
|
|
|
-
|
|
|
|
|
-@property (nonatomic,strong) NSDictionary *params;
|
|
|
|
|
-
|
|
|
|
|
-@end
|
|
|
|
|
-
|
|
|
|
|
-@implementation AMMapAnnotaion
|
|
|
|
|
-
|
|
|
|
|
-@end
|
|
|
|
|
|
|
+#import "AMMapAnnotaion.h"
|
|
|
|
|
+#import "AMAnnotationView.h"
|
|
|
|
|
|
|
|
#pragma mark - Button
|
|
#pragma mark - Button
|
|
|
|
|
|
|
@@ -39,7 +28,7 @@
|
|
|
|
|
|
|
|
#pragma mark - Location
|
|
#pragma mark - Location
|
|
|
|
|
|
|
|
-@interface LocationViewController () <MKMapViewDelegate>
|
|
|
|
|
|
|
+@interface LocationViewController () <MKMapViewDelegate,CLLocationManagerDelegate,AMAnnotationDelegate>
|
|
|
//@property (strong,nonatomic) NSString* locations ;
|
|
//@property (strong,nonatomic) NSString* locations ;
|
|
|
|
|
|
|
|
@property (nonatomic,assign) BOOL useGoogleMap;
|
|
@property (nonatomic,assign) BOOL useGoogleMap;
|
|
@@ -51,6 +40,8 @@
|
|
|
|
|
|
|
|
// 苹果原生的地图视图
|
|
// 苹果原生的地图视图
|
|
|
MKMapView *myMapView;
|
|
MKMapView *myMapView;
|
|
|
|
|
+ // 定位服务管理器
|
|
|
|
|
+ CLLocationManager *myLocManager;
|
|
|
}
|
|
}
|
|
|
- (BOOL)shouldAutorotate
|
|
- (BOOL)shouldAutorotate
|
|
|
{
|
|
{
|
|
@@ -573,26 +564,29 @@ didTapInfoWindowOfMarker:(GMSMarker *)marker
|
|
|
// 为MKMapView绑定委托
|
|
// 为MKMapView绑定委托
|
|
|
myMapView.delegate = self;
|
|
myMapView.delegate = self;
|
|
|
|
|
|
|
|
|
|
+ myMapView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
|
[self.view addSubview:myMapView];
|
|
[self.view addSubview:myMapView];
|
|
|
|
|
|
|
|
|
|
+ myMapView.rotateEnabled = NO;
|
|
|
// 创建经纬度坐标的结构体变量
|
|
// 创建经纬度坐标的结构体变量
|
|
|
// CLLocationCoordinate2DMake函数的第一个参数是纬度第二个参数是经度
|
|
// CLLocationCoordinate2DMake函数的第一个参数是纬度第二个参数是经度
|
|
|
CLLocationCoordinate2D c2d = CLLocationCoordinate2DMake(39.833333 , -98.3583333);
|
|
CLLocationCoordinate2D c2d = CLLocationCoordinate2DMake(39.833333 , -98.3583333);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
MKCoordinateSpan span = MKCoordinateSpanMake(180, 360);
|
|
MKCoordinateSpan span = MKCoordinateSpanMake(180, 360);
|
|
|
// 创建一个区域结构体变量
|
|
// 创建一个区域结构体变量
|
|
|
MKCoordinateRegion region = MKCoordinateRegionMake(c2d, span);
|
|
MKCoordinateRegion region = MKCoordinateRegionMake(c2d, span);
|
|
|
// 设置地图中心为指定区域
|
|
// 设置地图中心为指定区域
|
|
|
[myMapView setRegion:region animated:YES];
|
|
[myMapView setRegion:region animated:YES];
|
|
|
|
|
|
|
|
-// // 创建定位服务管理器对象
|
|
|
|
|
-// myLocManager = [[CLLocationManager alloc] init];
|
|
|
|
|
-// myLocManager.delegate = self;
|
|
|
|
|
-// [myLocManager requestWhenInUseAuthorization];
|
|
|
|
|
-// [myLocManager startUpdatingLocation];
|
|
|
|
|
-//
|
|
|
|
|
-// // 显示用户的位置
|
|
|
|
|
-// myMapView.showsUserLocation = YES;
|
|
|
|
|
|
|
+ // 创建定位服务管理器对象
|
|
|
|
|
+ myLocManager = [[CLLocationManager alloc] init];
|
|
|
|
|
+ myLocManager.delegate = self;
|
|
|
|
|
+ [myLocManager requestWhenInUseAuthorization];
|
|
|
|
|
+ [myLocManager startUpdatingLocation];
|
|
|
|
|
+
|
|
|
|
|
+ // 显示用户的位置
|
|
|
|
|
+ myMapView.showsUserLocation = YES;
|
|
|
|
|
+// myMapView.userTrackingMode = MKUserTrackingModeFollow;
|
|
|
|
|
|
|
|
NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:myMapView
|
|
NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:myMapView
|
|
|
attribute:NSLayoutAttributeTop
|
|
attribute:NSLayoutAttributeTop
|
|
@@ -654,6 +648,7 @@ didTapInfoWindowOfMarker:(GMSMarker *)marker
|
|
|
|
|
|
|
|
// 将大头针数据模型添加到MKMapView上管理
|
|
// 将大头针数据模型添加到MKMapView上管理
|
|
|
[myMapView addAnnotation:ann];
|
|
[myMapView addAnnotation:ann];
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -661,39 +656,46 @@ didTapInfoWindowOfMarker:(GMSMarker *)marker
|
|
|
|
|
|
|
|
// 当地图上添加了标注以后要执行的回调方法
|
|
// 当地图上添加了标注以后要执行的回调方法
|
|
|
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
|
|
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
|
|
|
- // 获取可复用的大头针视图
|
|
|
|
|
- MKAnnotationView *pinView = (id)[mapView dequeueReusableAnnotationViewWithIdentifier:@"PIN"];
|
|
|
|
|
-
|
|
|
|
|
- if (!pinView) { // 如果没有可重用的大头针视图就创建并指定重用标识
|
|
|
|
|
- pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PIN"];
|
|
|
|
|
|
|
+ if ([annotation isKindOfClass:[AMMapAnnotaion class]]) {
|
|
|
|
|
+ // 获取可复用的大头针视图
|
|
|
|
|
+ AMAnnotationView *pinView = (id)[mapView dequeueReusableAnnotationViewWithIdentifier:@"PIN"];
|
|
|
|
|
+
|
|
|
|
|
+ if (!pinView) { // 如果没有可重用的大头针视图就创建并指定重用标识
|
|
|
|
|
+ pinView = [[AMAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PIN"];
|
|
|
|
|
+ }
|
|
|
|
|
+ pinView.delegate = self;
|
|
|
|
|
+ pinView.image = [UIImage imageNamed:@"ic_marker"];
|
|
|
|
|
+
|
|
|
|
|
+// // 以气泡方式显示大头针的信息
|
|
|
|
|
+// pinView.canShowCallout = YES;
|
|
|
|
|
+// // 启用大头针掉下动画
|
|
|
|
|
+// // pinView.animatesDrop = YES;
|
|
|
|
|
+//
|
|
|
|
|
+// // UIImageView *headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
|
|
|
|
|
+// // headerImageView.layer.cornerRadius = 20;
|
|
|
|
|
+// // headerImageView.layer.masksToBounds = YES;
|
|
|
|
|
+// // headerImageView.image = [UIImage imageNamed:@"7.jpg"];
|
|
|
|
|
+// // headerImageView.userInteractionEnabled = YES;
|
|
|
|
|
+// // // 定制大头针气泡信息的左侧附加视图
|
|
|
|
|
+// // pinView.leftCalloutAccessoryView = headerImageView;
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// MapAccessoryButton *goButton = [MapAccessoryButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
+// if ([annotation isKindOfClass:[AMMapAnnotaion class]]) {
|
|
|
|
|
+// AMMapAnnotaion *ann = annotation;
|
|
|
|
|
+// goButton.params = ann.params;
|
|
|
|
|
+// }
|
|
|
|
|
+// goButton.frame = CGRectMake(0, 0, 40, 40);
|
|
|
|
|
+// [goButton setImage:[UIImage imageNamed:@"Forward"] forState:UIControlStateNormal];
|
|
|
|
|
+// [goButton addTarget:self action:@selector(goButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
+// // 定制大头针气泡信息的右侧附加视图
|
|
|
|
|
+// pinView.rightCalloutAccessoryView = goButton;
|
|
|
|
|
+
|
|
|
|
|
+ return pinView;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return nil; // 返回nil,系统使用蓝色圆点标识当前位置
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- pinView.image = [UIImage imageNamed:@"ic_marker"];
|
|
|
|
|
-
|
|
|
|
|
- // 以气泡方式显示大头针的信息
|
|
|
|
|
- pinView.canShowCallout = YES;
|
|
|
|
|
- // 启用大头针掉下动画
|
|
|
|
|
- // pinView.animatesDrop = YES;
|
|
|
|
|
-
|
|
|
|
|
- // UIImageView *headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
|
|
|
|
|
- // headerImageView.layer.cornerRadius = 20;
|
|
|
|
|
- // headerImageView.layer.masksToBounds = YES;
|
|
|
|
|
- // headerImageView.image = [UIImage imageNamed:@"7.jpg"];
|
|
|
|
|
- // headerImageView.userInteractionEnabled = YES;
|
|
|
|
|
- // // 定制大头针气泡信息的左侧附加视图
|
|
|
|
|
- // pinView.leftCalloutAccessoryView = headerImageView;
|
|
|
|
|
-
|
|
|
|
|
- AMMapAnnotaion *ann = annotation;
|
|
|
|
|
-
|
|
|
|
|
- MapAccessoryButton *goButton = [MapAccessoryButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
- goButton.params = ann.params;
|
|
|
|
|
- goButton.frame = CGRectMake(0, 0, 40, 40);
|
|
|
|
|
- [goButton setImage:[UIImage imageNamed:@"Forward"] forState:UIControlStateNormal];
|
|
|
|
|
- [goButton addTarget:self action:@selector(goButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
- // 定制大头针气泡信息的右侧附加视图
|
|
|
|
|
- pinView.rightCalloutAccessoryView = goButton;
|
|
|
|
|
-
|
|
|
|
|
- return pinView;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
|
|
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
|
|
@@ -706,7 +708,12 @@ didTapInfoWindowOfMarker:(GMSMarker *)marker
|
|
|
|
|
|
|
|
- (void) goButtonClicked:(MapAccessoryButton *) sender {
|
|
- (void) goButtonClicked:(MapAccessoryButton *) sender {
|
|
|
|
|
|
|
|
- self.params = sender.params;
|
|
|
|
|
|
|
+ self.params = [sender.params mutableCopy];
|
|
|
|
|
+ [self showUnknown];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)mapView:(MKMapView *)mapView didTapAnnotaionCallout:(AMMapAnnotaion *)annotation {
|
|
|
|
|
+ self.params = [annotation.params mutableCopy];
|
|
|
[self showUnknown];
|
|
[self showUnknown];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -716,12 +723,12 @@ didTapInfoWindowOfMarker:(GMSMarker *)marker
|
|
|
|
|
|
|
|
// 定位的位置发生改变后的回调方法
|
|
// 定位的位置发生改变后的回调方法
|
|
|
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
|
|
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
|
|
|
- // 从数组中取出第一个元素(包括当前的定位信息[经纬度、海拔、速度、方向等])
|
|
|
|
|
- CLLocation *location = [locations firstObject];
|
|
|
|
|
- // 创建一个新的区域
|
|
|
|
|
- MKCoordinateRegion newRegion = MKCoordinateRegionMake(location.coordinate, MKCoordinateSpanMake(0.1, 0.1));
|
|
|
|
|
- // 将地图位置设置到新的区域
|
|
|
|
|
- [myMapView setRegion:newRegion animated:YES];
|
|
|
|
|
|
|
+// // 从数组中取出第一个元素(包括当前的定位信息[经纬度、海拔、速度、方向等])
|
|
|
|
|
+// CLLocation *location = [locations firstObject];
|
|
|
|
|
+// // 创建一个新的区域
|
|
|
|
|
+// MKCoordinateRegion newRegion = MKCoordinateRegionMake(location.coordinate, MKCoordinateSpanMake(180, 360));
|
|
|
|
|
+// // 将地图位置设置到新的区域
|
|
|
|
|
+// [myMapView setRegion:newRegion animated:YES];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
|
|
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
|