关注谷歌地图上的用户位置

时间:2014-04-10 06:47:33

标签: ios google-maps gps gmsmapview

我在ios上有谷歌地图sdk并启用了userlocation = yes。 我希望在移动时通过GPS获取用户位置。我在文档中找不到任何方法,当用户继续移动时返回位置更新。 我希望不断地将用户置于屏幕中央,然后使用这些位置更新相机。

有什么意义吗? 有一种方法didchangecameraposition,当我在地图上应用手势时会更新,但不会在gps更新时更新。

1 个答案:

答案 0 :(得分:4)

您无法完全使用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];

位置管理员的代表:

- (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];


}
相关问题