Hi i am beginner in Ios and in my project i am using Google SDK for getting route when user walking or driving along the road
But i am not able to get current location and showing in my x code console 0.0 and 0.0(latitude and longitude values) please help me some one for getting current location
My code is below:-
#import "ViewController.h"
@interface ViewController ()
{
GMSMapView *_mapView;
NSMutableArray *_coordinates;
LRouteController *_routeController;
GMSPolyline *_polyline;
GMSMarker *_markerStart;
GMSMarker *_markerFinish;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.settings.myLocationButton = YES;
_mapView.myLocationEnabled = YES;
_mapView.delegate = self;
}
- (void)loadView{
CLLocation *myLocation = _mapView.myLocation;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(myLocation.coordinate.latitude, myLocation.coordinate.longitude);
marker.title = @"Current Location";
marker.map = _mapView;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:myLocation.coordinate.latitude
longitude:myLocation.coordinate.longitude
zoom:6];
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = _mapView;
NSLog(@"%f, %f", myLocation.coordinate.latitude, myLocation.coordinate.longitude);
}
#pragma mark - GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
_polyline.map = nil;
_markerStart.map = nil;
_markerFinish.map = nil;
[_coordinates addObject:[[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude]];
if ([_coordinates count] > 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 blueColor];
_polyline.map = _mapView;
}
}];
}
}
@end