Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2015 16:05
Show Gist options
  • Save anonymous/18e50db82365eadb5840 to your computer and use it in GitHub Desktop.
Save anonymous/18e50db82365eadb5840 to your computer and use it in GitHub Desktop.
50行開始
//
// ViewController.m
//
//
// Created by JazzHuang on 2015/10/15.
// Copyright © 2015年 Jazz. All rights reserved.
//
#import <GoogleMaps/GoogleMaps.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import "ViewController.h"
@interface ViewController ()<GMSMapViewDelegate,CLLocationManagerDelegate>
{
NSMutableArray * mylocations;
CLLocationManager *locationManager;
GMSPolyline * selfPolyLine;
BOOL isFirstLocationReceived;
CLLocation *currentLocations;
GMSMutablePath * path;
GMSMarker * destinationMarker;
};
@property (retain, nonatomic) IBOutlet GMSMapView *mapView_;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
locationManager =[[CLLocationManager alloc]init];
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
// locationManager.distanceFilter = 50;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.activityType = CLActivityTypeAutomotiveNavigation;
locationManager.delegate =self;
self.mapView_.delegate=self;
self.mapView_.myLocationEnabled = YES;
self.mapView_.settings.myLocationButton = YES;
[locationManager startUpdatingLocation];
// Do any additional setup after loading the view, typically from a nib.
}
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
currentLocations = locations.lastObject;
if (currentLocations.horizontalAccuracy < 0) {
return;
}
[mylocations addObject:currentLocations];
NSLog(@"myloc: %@ ",mylocations);
path = [GMSMutablePath path];
if (mylocations.count>1) {
CLLocationCoordinate2D coordinates[mylocations.count];
for (int i=0; i<mylocations.count; i++) {
coordinates[i] = [(CLLocation*)mylocations[i] coordinate];
[path addCoordinate:coordinates[i]];
selfPolyLine.path = path;
selfPolyLine.strokeColor =[UIColor blueColor];
selfPolyLine.strokeWidth = 6.f;
selfPolyLine.map = self.mapView_;
}
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)TrackingType:(id)sender {
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment