Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
Z
ZhiJi-Overseas
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lmj
ZhiJi-Overseas
Commits
8901206b
Commit
8901206b
authored
Jul 04, 2020
by
lmj_521aiau@163.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
applemap
parent
684ba8e8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
237 additions
and
98 deletions
+237
-98
ZJBaseMapViewController.m
ZhiJi/Classes/Map/Controller/ZJBaseMapViewController.m
+50
-44
ZJFriendTrackMapViewController.m
...i/Classes/Map/Controller/ZJFriendTrackMapViewController.m
+187
-54
No files found.
ZhiJi/Classes/Map/Controller/ZJBaseMapViewController.m
View file @
8901206b
...
...
@@ -7,10 +7,12 @@
//
#import "ZJBaseMapViewController.h"
#import <MapKit/MapKit.h>
@interface
ZJBaseMapViewController
()
<
MAMapViewDelegate
,
XMPopupListViewDelegate
>
@interface
ZJBaseMapViewController
()
<
MAMapViewDelegate
,
XMPopupListViewDelegate
,
MKMapViewDelegate
>
@property
(
nonatomic
,
strong
)
MAMapView
*
mapView
;
@property
(
nonatomic
,
strong
)
MKMapView
*
mapView
;
//@property (nonatomic, strong) MAMapView *mapView;
@property
(
nonatomic
,
strong
)
UIButton
*
gpsButton
;
@property
(
nonatomic
,
strong
)
ZJMapViewPersonCardView
*
cardView
;
...
...
@@ -40,41 +42,32 @@
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
2
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
[
self
getFriendList
];
});
if
([
ZJUserInfoManager
CNLanguage
])
{
self
.
mapView
.
mapLanguage
=
@0
;
[
self
.
mapView
performSelector
:
NSSelectorFromString
(
@"setMapLanguage:"
)
withObject
:
@
(
0
)];
}
else
{
self
.
mapView
.
mapLanguage
=
@1
;
[
self
.
mapView
performSelector
:
NSSelectorFromString
(
@"setMapLanguage:"
)
withObject
:
@
(
1
)];
}
}
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
self
.
navigationController
setNavigationBarHidden
:
true
animated
:
true
];
if
([
ZJUserInfoManager
CNLanguage
])
{
self
.
mapView
.
mapLanguage
=
@0
;
[
self
.
mapView
performSelector
:
NSSelectorFromString
(
@"setMapLanguage:"
)
withObject
:
@
(
0
)];
}
else
{
self
.
mapView
.
mapLanguage
=
@1
;
[
self
.
mapView
performSelector
:
NSSelectorFromString
(
@"setMapLanguage:"
)
withObject
:
@
(
1
)];
}
}
-
(
void
)
setupUI
{
///初始化地图
self
.
mapView
=
[[
M
A
MapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
self
.
mapView
=
[[
M
K
MapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
self
.
mapView
.
mapType
=
0
;
_mapView
.
showsWorldMap
=
@YES
;
[
self
.
mapView
performSelector
:
@selector
(
setShowsWorldMap
:)
withObject
:
@
(
YES
)];
// _mapView.showsWorldMap = @YES;
// [self.mapView performSelector:@selector(setShowsWorldMap:) withObject:@(YES)];
if
([
ZJUserInfoManager
CNLanguage
])
{
// self.mapView.mapLanguage = @0;
// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(0)];
}
else
{
// self.mapView.mapLanguage = @1;
// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(1)];
}
_mapView
.
autoresizingMask
=
UIViewAutoresizingFlexibleWidth
|
UIViewAutoresizingFlexibleHeight
;
///把地图添加至view
[
self
.
view
addSubview
:
_mapView
];
_mapView
.
delegate
=
self
;
_mapView
.
zoomLevel
=
14
;
//
_mapView.zoomLevel = 14;
_mapView
.
showsScale
=
false
;
_mapView
.
showsCompass
=
false
;
...
...
@@ -126,29 +119,29 @@
};
}
-
(
void
)
mapView
:
(
UIView
*
)
mapView
regionDidChangeAnimated
:
(
BOOL
)
animated
{
// if(mapView.isHidden) {
// return;
//- (void)mapView:(UIView *)mapView regionDidChangeAnimated:(BOOL)animated {
//// if(mapView.isHidden) {
//// return;
//// }
////
//// if(self.isSwitching) {
//// self.isSwitching = NO;
//// return;
//// }
//
//// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(1)];
//// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(0)];
//
// if([mapView isKindOfClass:[MAMapView class]]) {
// if(!AMapDataAvailableForCoordinate(self.mapView.centerCoordinate)) {
//
// }
// } else {
// if(AMapDataAvailableForCoordinate(self.mapView.centerCoordinate)) {
//
// if(self.isSwitching) {
// self.isSwitching = NO;
// return;
// }
// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(1)];
// [self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(0)];
if
([
mapView
isKindOfClass
:[
MAMapView
class
]])
{
if
(
!
AMapDataAvailableForCoordinate
(
self
.
mapView
.
centerCoordinate
))
{
}
}
else
{
if
(
AMapDataAvailableForCoordinate
(
self
.
mapView
.
centerCoordinate
))
{
}
}
}
// }
//}
#pragma mark 好友列表
-
(
void
)
getFriendList
{
...
...
@@ -251,7 +244,7 @@
MAPointAnnotation
*
pointAnnotation
=
[[
MAPointAnnotation
alloc
]
init
];
pointAnnotation
.
coordinate
=
CLLocationCoordinate2DMake
(
lat
,
lon
);
pointAnnotation
.
title
=
@"latestLocation"
;
[
_self
.
mapView
addAnnotation
:
pointAnnotation
];
[
_self
.
mapView
addAnnotation
:
(
id
<
MKAnnotation
>
)
pointAnnotation
];
[
_self
.
mapView
setCenterCoordinate
:
pointAnnotation
.
coordinate
animated
:
false
];
}
else
{
...
...
@@ -279,6 +272,19 @@
annotationView
.
enabled
=
NO
;
return
annotationView
;
}
else
if
([
annotation
isKindOfClass
:[
MKUserLocation
class
]]){
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier3"
;
MKAnnotationView
*
annotationView
=
(
MKAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
annotationView
==
nil
)
{
annotationView
=
[[
MKAnnotationView
alloc
]
initWithAnnotation
:(
id
<
MKAnnotation
>
)
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
.
canShowCallout
=
YES
;
}
annotationView
.
image
=
[
UIImage
imageNamed
:
@"userPosition"
];
annotationView
.
enabled
=
NO
;
return
(
MAAnnotationView
*
)
annotationView
;
}
return
nil
;
}
...
...
ZhiJi/Classes/Map/Controller/ZJFriendTrackMapViewController.m
View file @
8901206b
...
...
@@ -18,10 +18,12 @@
#import "AlertControllerTool.h"
#import <CoreLocation/CoreLocation.h>
#import "BaseWebViewController.h"
#import <MapKit/MapKit.h>
@interface
ZJFriendTrackMapViewController
()
<
MAMapViewDelegate
>
@interface
ZJFriendTrackMapViewController
()
<
MAMapViewDelegate
,
MKMapViewDelegate
,
CAAnimationDelegate
>
@property
(
nonatomic
,
strong
)
MAMapView
*
mapView
;
@property
(
nonatomic
,
strong
)
MKMapView
*
mapView
;
//@property (nonatomic, strong) MAMapView *mapView;
@property
(
nonatomic
,
strong
)
UIButton
*
gpsButton
;
@property
(
nonatomic
,
strong
)
ZJUserTrackTimeView
*
trackTimeView
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
ZJLocationModel
*>
*
locations
;
...
...
@@ -30,12 +32,18 @@
@property
(
strong
,
nonatomic
)
NSDate
*
endDate
;
///全轨迹overlay
@property
(
strong
,
nonatomic
)
M
A
Polyline
*
commonPolyline
;
@property
(
strong
,
nonatomic
)
M
K
Polyline
*
commonPolyline
;
///车头方向跟随转动
@property
(
nonatomic
,
strong
)
MAAnimatedAnnotation
*
track
;
@property
(
nonatomic
,
strong
)
NSArray
*
distanceArray
;
@property
(
nonatomic
,
assign
)
double
sumDistance
;
@property
(
nonatomic
,
strong
)
ZJAlertView
*
alertView
;
@property
(
nonatomic
,
strong
)
CAShapeLayer
*
shapeLayer
;
@end
@implementation
ZJFriendTrackMapViewController
...
...
@@ -86,7 +94,6 @@
self
.
alertView
.
alertSubtitle
.
text
=
kLocalizedString
(
@"track_friend_authority_alert"
);
}
[
self
.
alertView
.
leftButton
addTapBlock
:
^
(
UITapGestureRecognizer
*
tap
)
{
NSLog
(
@"%@"
,
@"leftButton"
);
...
...
@@ -119,7 +126,8 @@
-
(
void
)
setupUI
{
///初始化地图
self
.
mapView
=
[[
MAMapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
// self.mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
self
.
mapView
=
[[
MKMapView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
_mapView
.
autoresizingMask
=
UIViewAutoresizingFlexibleWidth
|
UIViewAutoresizingFlexibleHeight
;
///把地图添加至view
[
self
.
view
addSubview
:
_mapView
];
...
...
@@ -128,7 +136,7 @@
_mapView
.
showsUserLocation
=
false
;
_mapView
.
delegate
=
self
;
_mapView
.
zoomLevel
=
14
;
//
_mapView.zoomLevel = 14;
_mapView
.
showsScale
=
false
;
_mapView
.
showsCompass
=
false
;
...
...
@@ -161,7 +169,9 @@
self
.
track
=
[[
MAAnimatedAnnotation
alloc
]
init
];
self
.
track
.
title
=
@"pointReuseIndetifier1"
;
[
self
.
mapView
addAnnotation
:
self
.
track
];
// self.track = [[MKPointAnnotation alloc] init];
// self.track.title = @"pointReuseIndetifier1";
[
self
.
mapView
addAnnotation
:(
id
<
MKAnnotation
>
)
self
.
track
];
}
-
(
void
)
drawLineAction
{
...
...
@@ -171,27 +181,27 @@
[
self
.
mapView
removeOverlay
:
self
.
commonPolyline
];
// need get user location info
if
([
CLLocationManager
locationServicesEnabled
]
&&
([
CLLocationManager
authorizationStatus
]
==
kCLAuthorizationStatusAuthorizedWhenInUse
||
[
CLLocationManager
authorizationStatus
]
==
kCLAuthorizationStatusNotDetermined
||
[
CLLocationManager
authorizationStatus
]
==
kCLAuthorizationStatusAuthorized
))
{
// do nothing
}
else
if
([
CLLocationManager
authorizationStatus
]
==
kCLAuthorizationStatusDenied
)
{
//定位不能用
[
AlertControllerTool
alertControllerWithTitle
:
@"打开定位开关"
message
:
kLocalizedString
(
@"alert_location_service"
)
cancelTitle
:
kLocalizedString
(
@"alert_cancel"
)
cancelBlock
:^
{
}
confirm
:
kLocalizedString
(
@"alert_setting"
)
confirmBlock
:^
(
id
s
)
{
NSURL
*
url
=
[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
];
if
([[
UIApplication
sharedApplication
]
canOpenURL
:
url
])
{
if
(
@available
(
iOS
10
.
0
,
*
))
{
[[
UIApplication
sharedApplication
]
openURL
:
url
options
:@{}
completionHandler
:
nil
];
}
else
{
[[
UIApplication
sharedApplication
]
openURL
:
url
];
}
}
}
finishBlock
:
nil
];
return
;
}
//
if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {
//
// do nothing
//
} else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
//
//定位不能用
//
[AlertControllerTool alertControllerWithTitle:@"打开定位开关" message:kLocalizedString(@"alert_location_service") cancelTitle:kLocalizedString(@"alert_cancel") cancelBlock:^{
//
} confirm:kLocalizedString(@"alert_setting") confirmBlock:^(id s) {
//
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
//
if([[UIApplication sharedApplication] canOpenURL:url]) {
//
if (@available(iOS 10.0, *)) {
//
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
//
}else{
//
[[UIApplication sharedApplication] openURL:url];
//
}
//
}
//
} finishBlock:nil];
//
return;
//
}
MAPointAnnotation
*
pointAnnotation1
=
[[
MAPointAnnotation
alloc
]
init
];
pointAnnotation1
.
coordinate
=
CLLocationCoordinate2DMake
(
self
.
locations
.
firstObject
.
latitude
,
self
.
locations
.
firstObject
.
longitude
);
pointAnnotation1
.
title
=
@"start"
;
[
self
.
mapView
addAnnotation
:
pointAnnotation1
];
[
self
.
mapView
addAnnotation
:
(
id
<
MKAnnotation
>
)
pointAnnotation1
];
//构造折线数据对象
CLLocationCoordinate2D
commonPolylineCoords
[
self
.
locations
.
count
];
...
...
@@ -204,12 +214,14 @@
MAPointAnnotation
*
pointAnnotation2
=
[[
MAPointAnnotation
alloc
]
init
];
pointAnnotation2
.
coordinate
=
CLLocationCoordinate2DMake
(
self
.
locations
.
lastObject
.
latitude
,
self
.
locations
.
lastObject
.
longitude
);
pointAnnotation2
.
title
=
@"end"
;
[
self
.
mapView
addAnnotation
:
pointAnnotation2
];
[
self
.
mapView
addAnnotation
:
(
id
<
MKAnnotation
>
)
pointAnnotation2
];
//构造折线对象
MAPolyline
*
commonPolyline
=
[
MAPolyline
polylineWithCoordinates
:
commonPolylineCoords
count
:
self
.
locations
.
count
];
// MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count];
// self.commonPolyline = commonPolyline;
MKPolyline
*
commonPolyline
=
[
MKPolyline
polylineWithCoordinates
:
commonPolylineCoords
count
:
self
.
locations
.
count
];
self
.
commonPolyline
=
commonPolyline
;
// self.commonPolyline.boundingMapRect
//在地图上添加折线对象
[
self
.
mapView
addOverlay
:
commonPolyline
];
...
...
@@ -236,8 +248,26 @@
[
weakSelf
.
trackTimeView
.
trackButton
setEnabled
:
true
];
[
weakSelf
.
trackTimeView
.
trackButton
setSelected
:
false
];
}];
[
self
.
mapView
setVisibleMapRect
:
self
.
commonPolyline
.
boundingMapRect
edgePadding
:
UIEdgeInsetsMake
(
250
,
50
,
50
,
50
)
animated
:
true
];
MKMapRect
rect
=
MKMapRectMake
(
self
.
commonPolyline
.
boundingMapRect
.
origin
.
x
,
self
.
commonPolyline
.
boundingMapRect
.
origin
.
y
,
self
.
commonPolyline
.
boundingMapRect
.
size
.
width
,
self
.
commonPolyline
.
boundingMapRect
.
size
.
height
);
[
self
.
mapView
setVisibleMapRect
:
rect
edgePadding
:
UIEdgeInsetsMake
(
250
,
50
,
50
,
50
)
animated
:
true
];
//
// CGPoint *points = [self pointsForCoordinates:commonPolylineCoords count:count];
// CGPathRef path = [self pathForPoints:points count:count];
// [self initShapeLayerWithPath:path];
// self.shapeLayer.frame = self.mapView.bounds;
//
// CAAnimation *shapeLayerAnimation = [self constructShapeLayerAnimation];
// shapeLayerAnimation.delegate = self;
// shapeLayerAnimation.removedOnCompletion = NO;
// shapeLayerAnimation.fillMode = kCAFillModeForwards;
//
// [self.shapeLayer addAnimation:shapeLayerAnimation forKey:@"shape"];
//
// [self.mapView.layer addSublayer:self.shapeLayer];
}
-
(
ZJAlertView
*
)
getAlertView
:
(
NSString
*
)
title
subtitle
:
(
NSString
*
)
subtitle
leftButtonTitle
:
(
NSString
*
)
leftButtonTitle
rightButtonTitle
:
(
NSString
*
)
rightButtonTitle
{
...
...
@@ -259,29 +289,40 @@
#pragma mark - Map Delegate
-
(
M
AAnnotationView
*
)
mapView
:
(
MAMapView
*
)
mapView
viewForAnnotation
:
(
id
<
MA
Annotation
>
)
annotation
{
-
(
M
KAnnotationView
*
)
mapView
:
(
MKMapView
*
)
mapView
viewForAnnotation
:
(
id
<
MK
Annotation
>
)
annotation
{
if
(
annotation
==
self
.
track
)
{
if
(
annotation
==
(
id
<
MKAnnotation
>
)
self
.
track
)
{
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier1"
;
MAAnnotationView
*
annotationView
=
(
MAAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
// MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
// if(!annotationView) {
// annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
//
// annotationView.canShowCallout = YES;
//
// UIImage *imge = [UIImage imageNamed:@"map_track_move_icon"];
// annotationView.image = imge;
//
// }
MKAnnotationView
*
annotationView
=
(
MKAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
!
annotationView
)
{
annotationView
=
[[
M
AAnnotationView
alloc
]
initWithAnnotation
:
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
=
[[
M
KAnnotationView
alloc
]
initWithAnnotation
:(
id
<
MKAnnotation
>
)
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
.
canShowCallout
=
YES
;
UIImage
*
imge
=
[
UIImage
imageNamed
:
@"map_track_move_icon"
];
annotationView
.
image
=
imge
;
// UIImage *imge = [UIImage imageNamed:@"map_track_move_icon"];
// annotationView.image = imge;
}
return
annotationView
;
}
else
if
([
annotation
isKindOfClass
:[
MAPointAnnotation
class
]])
{
}
else
if
([
annotation
isKindOfClass
:[
MAPointAnnotation
class
]])
{
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier
3
"
;
M
AAnnotationView
*
annotationView
=
(
MA
AnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier
2
"
;
M
KAnnotationView
*
annotationView
=
(
MK
AnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
annotationView
==
nil
)
{
annotationView
=
[[
M
AAnnotationView
alloc
]
initWithAnnotation
:
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
=
[[
M
KAnnotationView
alloc
]
initWithAnnotation
:(
id
<
MKAnnotation
>
)
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
.
canShowCallout
=
YES
;
}
...
...
@@ -291,28 +332,71 @@
}
else
if
([
annotation
.
title
isEqualToString
:
@"end"
])
{
annotationView
.
enabled
=
NO
;
annotationView
.
image
=
[
UIImage
imageNamed
:
kLocalizedString
(
@"map_track_end_icon"
)];
}
else
{
}
// else {
// annotationView.enabled = NO;
// annotationView.image = [UIImage imageNamed:@"userPosition"];
// }
return
(
MKAnnotationView
*
)
annotationView
;
}
else
if
([
annotation
isKindOfClass
:[
MKUserLocation
class
]]){
NSString
*
pointReuseIndetifier
=
@"pointReuseIndetifier1"
;
MKAnnotationView
*
annotationView
=
(
MKAnnotationView
*
)[
mapView
dequeueReusableAnnotationViewWithIdentifier
:
pointReuseIndetifier
];
if
(
annotationView
==
nil
)
{
annotationView
=
[[
MKAnnotationView
alloc
]
initWithAnnotation
:(
id
<
MKAnnotation
>
)
annotation
reuseIdentifier
:
pointReuseIndetifier
];
annotationView
.
canShowCallout
=
YES
;
}
annotationView
.
enabled
=
NO
;
annotationView
.
image
=
[
UIImage
imageNamed
:
@"userPosition"
];
}
return
annotationView
;
}
// else{
//
// NSString *pointReuseIndetifier = @"pointReuseIndetifier3";
// MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
// if (annotationView == nil) {
// annotationView = [[MKAnnotationView alloc] initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:pointReuseIndetifier];
// annotationView.canShowCallout = YES;
// }
//
// if ([annotation.title isEqualToString:@"start"]) {
// annotationView.enabled = NO;
// annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_start_icon")];
// } else if ([annotation.title isEqualToString:@"end"]) {
// annotationView.enabled = NO;
// annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")];
// }
// return annotationView;
// }
return
nil
;
}
/// 设置折线的样式
-
(
M
AOverlayRenderer
*
)
mapView
:
(
MAMapView
*
)
mapView
rendererForOverlay
:
(
id
<
MA
Overlay
>
)
overlay
-
(
M
KOverlayRenderer
*
)
mapView
:
(
MKMapView
*
)
mapView
rendererForOverlay
:
(
id
<
MK
Overlay
>
)
overlay
{
if
([
overlay
isKindOfClass
:[
MAPolyline
class
]])
{
MAPolylineRenderer
*
polylineRenderer
=
[[
MAPolylineRenderer
alloc
]
initWithPolyline
:
overlay
];
MAPolylineRenderer
*
polylineRenderer
=
[[
MAPolylineRenderer
alloc
]
initWithPolyline
:
(
MAPolyline
*
)
overlay
];
polylineRenderer
.
lineWidth
=
4
.
f
;
polylineRenderer
.
strokeColor
=
[
UIColor
colorWithHex
:
0x568EFC
];
polylineRenderer
.
lineJoinType
=
kMALineJoinRound
;
polylineRenderer
.
lineCapType
=
kMALineCapRound
;
return
polylineRenderer
;
return
(
MKOverlayRenderer
*
)
polylineRenderer
;
}
else
if
([
overlay
isKindOfClass
:[
MKPolyline
class
]]){
MKPolylineRenderer
*
render
=
[[
MKPolylineRenderer
alloc
]
initWithOverlay
:
overlay
];
render
.
lineWidth
=
4
.
f
;
render
.
strokeColor
=
[
UIColor
colorWithHex
:
0x568EFC
];
render
.
lineJoin
=
kMALineJoinRound
;
render
.
lineCap
=
kMALineCapRound
;
return
render
;
}
return
nil
;
}
...
...
@@ -442,7 +526,7 @@
double
lat
=
[
response
[
@"result"
][
@"data"
][
@"lat"
]
doubleValue
];
double
lon
=
[
response
[
@"result"
][
@"data"
][
@"lon"
]
doubleValue
];
M
APointAnnotation
*
pointAnnotation
=
[[
MA
PointAnnotation
alloc
]
init
];
M
KPointAnnotation
*
pointAnnotation
=
[[
MK
PointAnnotation
alloc
]
init
];
pointAnnotation
.
coordinate
=
CLLocationCoordinate2DMake
(
lat
,
lon
);
pointAnnotation
.
title
=
@"latestLocation"
;
[
_self
.
mapView
addAnnotation
:
pointAnnotation
];
...
...
@@ -455,7 +539,56 @@
}
failure
:^
(
NSError
*
_Nonnull
error
)
{
NSLog
(
@"失败"
);
}];
}
#pragma mark - 构造shapeLayer
-
(
void
)
initShapeLayerWithPath
:
(
CGPathRef
)
path
{
self
.
shapeLayer
=
[[
CAShapeLayer
alloc
]
init
];
self
.
shapeLayer
.
strokeColor
=
[
UIColor
greenColor
].
CGColor
;
self
.
shapeLayer
.
fillColor
=
[
UIColor
clearColor
].
CGColor
;
self
.
shapeLayer
.
lineJoin
=
kCALineCapRound
;
self
.
shapeLayer
.
path
=
path
;
}
#pragma mark - 经纬度转屏幕坐标, 调用者负责释放内存!
-
(
CGPoint
*
)
pointsForCoordinates
:
(
CLLocationCoordinate2D
*
)
coordinates
count
:
(
NSUInteger
)
count
{
if
(
coordinates
==
NULL
||
count
<=
1
){
return
NULL
;
}
/* 申请屏幕坐标存储空间. */
CGPoint
*
points
=
(
CGPoint
*
)
malloc
(
count
*
sizeof
(
CGPoint
));
/* 经纬度转换为屏幕坐标. */
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
CGPoint
point
=
CGPointMake
([
self
.
mapView
convertCoordinate
:
coordinates
[
i
]
toPointToView
:
self
.
mapView
].
x
,
[
self
.
mapView
convertCoordinate
:
coordinates
[
i
]
toPointToView
:
self
.
mapView
].
y
);
points
[
i
]
=
point
;
}
return
points
;
}
#pragma mark - 构建path, 调用者负责释放内存!
-
(
CGMutablePathRef
)
pathForPoints
:
(
CGPoint
*
)
points
count
:
(
NSUInteger
)
count
{
if
(
points
==
NULL
||
count
<=
1
){
return
NULL
;
}
CGMutablePathRef
path
=
CGPathCreateMutable
();
CGPathAddLines
(
path
,
NULL
,
points
,
count
);
return
path
;
}
#pragma mark - 构建shapeLayer的basicAnimation
-
(
CAAnimation
*
)
constructShapeLayerAnimation
{
CABasicAnimation
*
theStrokeAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
theStrokeAnimation
.
duration
=
3
;
theStrokeAnimation
.
fromValue
=
@0.f
;
theStrokeAnimation
.
toValue
=
@1.f
;
theStrokeAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
return
theStrokeAnimation
;
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment