-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGoogleMapsCategories.m
90 lines (70 loc) · 2.49 KB
/
GoogleMapsCategories.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// GoogleMapsCategories.m
// FTLibrary2
//
// Created by Baldoph Pourprix on 11/04/2013.
// Copyright (c) 2013 Fuerte International. All rights reserved.
//
#import <GoogleMaps/GoogleMaps.h>
#import <MapKit/MapKit.h>
#import "FT2GMapsRoute.h"
#import "NSData+Coordinates.h"
@implementation GMSMapView (Additions)
- (void)zoomToCoordinateBounds:(GMSCoordinateBounds *)coordinateBounds animated:(BOOL)animated
{
MKMapPoint northEastMapPoint = MKMapPointForCoordinate(coordinateBounds.northEast); // top right
MKMapPoint southWestMapPoint = MKMapPointForCoordinate(coordinateBounds.southWest); // bottom left
float mapViewWidth = self.frame.size.width;
float mapViewHeight = self.frame.size.height;
MKMapPoint centrePoint = MKMapPointMake(
(northEastMapPoint.x + southWestMapPoint.x) / 2,
(northEastMapPoint.y + southWestMapPoint.y) / 2);
CLLocationCoordinate2D centreLocation = MKCoordinateForMapPoint(centrePoint);
double mapScaleWidth = mapViewWidth / fabs(southWestMapPoint.x - northEastMapPoint.x);
double mapScaleHeight = mapViewHeight / fabs(southWestMapPoint.y - northEastMapPoint.y);
double mapScale = MIN(mapScaleWidth, mapScaleHeight);
double zoomLevel = 20 + log2(mapScale);
GMSCameraPosition *cameraPosition = [GMSCameraPosition
cameraWithLatitude: centreLocation.latitude
longitude: centreLocation.longitude
zoom: zoomLevel];
if (animated) {
[self animateToCameraPosition:cameraPosition];
} else {
self.camera = cameraPosition;
}
}
@end
@implementation FT2GMapsRoute (GoogleMap)
- (GMSPath *)path
{
if (_path == nil) {
GMSMutablePath *path = [[GMSMutablePath alloc] init];
NSArray *locations = self.polylineLocations;
[locations enumerateObjectsUsingBlock:^(CLLocation *location, NSUInteger idx, BOOL *stop) {
[path addCoordinate:location.coordinate];
}];
_path = path.copy;
}
return _path;
}
- (GMSCoordinateBounds *)bounds
{
if (_bounds == nil) {
_bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:self.northEastBound coordinate:self.southWestBound];
}
return _bounds;
}
@end
@implementation NSArray (GoogleMap)
/* return a path for the array if all the objects are NSValues of CLLocationCoordinate2D */
- (GMSPath *)path
{
GMSMutablePath *path = [[GMSMutablePath alloc] init];
[self enumerateObjectsUsingBlock:^(NSData *locationData, NSUInteger idx, BOOL *stop) {
CLLocationCoordinate2D coordinates = [locationData coordinatesFromData];
[path addCoordinate:coordinates];
}];
return path;
}
@end