Hi i am beginner for using Google maps in Ios and i my project i am trying to plot the route when user walking or driving along the road but here current location is getting but route is not plotting when user walking laong road if any body know about this please help me
My code below:-
#import "ViewController.h"
@interface ViewController ()
{
GMSMapView *_mapView;
NSMutableArray *_coordinates;
LRouteController *_routeController;
GMSPolyline *_polyline;
GMSMarker *_markerStart;
GMSMarker *_markerFinish;
CLLocationManager *locationManager_;
}
@end
@implementation ViewController
- (void)viewDidLoad{
[super viewDidLoad];
_markerStart = [[GMSMarker alloc]init];
_markerFinish = [[GMSMarker alloc]init];
_coordinates = [[NSMutableArray alloc]init];
locationManager_ = [[CLLocationManager alloc] init];
locationManager_.delegate = self;
[locationManager_ setDistanceFilter:10.0f];
locationManager_.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager_ requestAlwaysAuthorization];
[locationManager_ startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
_polyline.map = nil;
_markerStart.map = nil;
_markerFinish.map = nil;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude
longitude:newLocation.coordinate.longitude
zoom:16];
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
_mapView.myLocationEnabled = YES;
_mapView.settings.myLocationButton = YES;
self.view = _mapView;
_markerStart.position = CLLocationCoordinate2DMake(newLocation.coordinate.latitude, newLocation.coordinate.longitude);
_markerStart.title = @"CurrentLocation";
_markerStart.snippet = @"Hello";
_markerStart.map = _mapView;
_markerFinish.title = @"Finish";
_markerFinish.snippet = @"End";
_markerFinish.map = _mapView;
NSLog(@"didUpdateToLocation: %@", newLocation);
NSLog(@"new location %f",newLocation.coordinate.latitude);
NSLog(@"new location %f",newLocation.coordinate.longitude);
[_coordinates addObject:[[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude]];
NSLog(@"array list %lu",(unsigned long)_coordinates.count);
if ([_coordinates count] > 1)
{
NSLog(@"1");
[_routeController getPolylineWithLocations:_coordinates travelMode:TravelModeDriving andCompletitionBlock:^(GMSPolyline *polyline, NSError *error) {
if (error)
{
NSLog(@"%@", error);
}
else if (!polyline)
{
NSLog(@"No route");
[_coordinates removeAllObjects];
}
else
{
_markerStart.position = [[_coordinates objectAtIndex:0] coordinate];
_markerStart.map = _mapView;
_markerFinish.position = [[_coordinates lastObject] coordinate];
_markerFinish.map = _mapView;
_polyline = polyline;
_polyline.strokeWidth = 3;
_polyline.strokeColor = [UIColor redColor];
_polyline.map = _mapView;
}
}];
}
}
@end
But route is not plotting please help me some one
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire