For my iOS app (building in iOS7),i need to show user\'s current location when the app load.I am using Google Maps iOS SDK. I am follo
It seems Google Maps iOS SDKcannot access to the device position.
So you have to retrieve the position by using CLLocationManagerof iOS.
First, add the CoreLocation.framework to your project :
Project NavigatorBuild PhasesCoreLocation.framework in the Link Binary with LibrariesThen all you need to do is to follow the basic exemple of Apple documentation.
Create a CLLocationManager probably in your ViewDidLoad:
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
//Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
// Set a movement threshold for new events.
locationManager.distanceFilter = 500; // meters
[locationManager startUpdatingLocation];
With the CLLocationManagerDelegate every time the position is updated, you can update the user position on your Google Maps :
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power.
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// Update your marker on your map using location.coordinate.latitude
//and location.coordinate.longitude);
}
}