ank*_*rck 1 gps google-maps ios gmsmapview
我在 ios 上有谷歌地图 sdk 并启用了 userlocation = yes。我想在他移动时通过 GPS 获取用户位置。我在文档中找不到任何在用户不断移动时返回位置更新的方法。我想让我的用户保持在屏幕的中心,然后使用这些位置不断更新相机。
这有什么要点吗?有一种方法 didchangecameraposition 会在我在地图上应用手势时更新,但不会在 gps 更新时更新。
你不能完全用谷歌地图 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];
Run Code Online (Sandbox Code Playgroud)
位置经理的代表:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3364 次 |
| 最近记录: |