在谷歌地图上关注用户位置 [英] Follow user location on google maps

查看:318
本文介绍了在谷歌地图上关注用户位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS上使用google maps sdk并启用userlocation = yes。
我想在他移动时通过GPS获取用户位置。在用户不断移动的情况下,我无法在文档中找到任何返回位置更新的方法。
我想通过不断更新相机使用这些位置来将我的用户保持在屏幕的中心位置。

I have google maps sdk on ios and enabled userlocation = yes. I want to get the user location via GPS when he moves. I could not find any method in document that returns me location updates as the user keeps moving. I want to keep my user in center of the screen by continuously then updating the camera using these location.

这方面的任何一点?
有一个方法didchangecameraposition,当我在地图上应用手势时更新,但当gps得到更新时不会更新。

Any points on this? There is a method didchangecameraposition which updates when i apply gestures on maps, but not when the gps gets updated.

推荐答案

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

You cannot do it totally with the Google maps SDK, you got to use the CLLocationManger framework to get the location updates.

初始化您的locationManager以注册重要的位置更改并正确设置委托

Initialize your locationManager to register for significant location changes and set up the delegate properly

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


}

这篇关于在谷歌地图上关注用户位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆