跟踪谷歌地图上的用户位置

我有谷歌地图sdk在iOS和启用userlocation =是。 我想在移动时通过GPS获取用户位置。 在用户不断移动的情况下,我无法在文档中find任何返回位置更新的方法。 我想保持我的用户在屏幕中心不断更新相机使用这些位置。

这个有什么意思? 有一个方法didchangecameraposition更新时,我在地图上应用手势,但不是当GPS更新。

您无法完全使用Google地图SDK,您必须使用CLLocationManger框架来获取位置更新。

初始化您的locationManager以注册重大位置更改并正确设置代理

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, set according to the required value. [locationManager startUpdatingLocation]; 

位置pipe理员的代表:

 - (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 by using the GMSCameraUpdate object GMSCameraUpdate *locationUpdate = [GMSCameraUpdate setTarget:location.coordinate zoom:YOUR_ZOOM_LEVEL]; [mapView_ animateWithCameraUpdate:locationUpdate]; }