It seems Google Maps iOS SDK
cannot access to the device position.
So you have to retrieve the position by using CLLocationManager
of iOS
.
First, add the CoreLocation.framework
to your project :
- Go in
Project Navigator
- Select your project
- Click on the tab
Build Phases
- Add the
CoreLocation.framework
in theLink Binary with Libraries
Then all you need to do is to follow the basic exemple of Apple documentation.
Create a
CLLocationManager
probably in yourViewDidLoad
: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);
}
}