【问题标题】:Follow user location on google maps在谷歌地图上关注用户位置
【发布时间】:2014-04-10 06:47:33
【问题描述】:

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

对此有何看法? 有一种方法 didchangecameraposition 会在我在地图上应用手势时更新,但在 gps 更新时不会更新。

【问题讨论】:

    标签: ios google-maps gps gmsmapview


    【解决方案1】:

    您不能完全使用 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];
    
    
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 2014-02-18
    • 2012-11-25
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多