gpt4 book ai didi

ios - 如何在 google sdk ios 中移动 gmsmapview 上的标记

转载 作者:行者123 更新时间:2023-11-29 01:17:10 25 4
gpt4 key购买 nike

我想在纬度的基础上移动标记,我正在不断地做这件事,如下所示...

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations   (NSArray<CLLocation *> *)locations 
{

CLLocationCoordinate2D coor2D = CLLocationCoordinate2DMake(longitude, latitude);
self.marker.position = coor2D;

}

该方法正在更新很长时间,但标记没有移动,为什么...在 info.plist 中我添加了.. enter image description here

最佳答案

假设您已经设置了委托(delegate),请尝试此操作:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations   (NSArray<CLLocation *> *)locations 
{

CLLocationCoordinate2D coor2D = CLLocationCoordinate2DMake(longitude, latitude);
self.marker.position = coor2D;

[self.mapView animateToLocation:coord2D.coordinate]
}

如果您只想更新当前位置。您可能应该为此使用 KVO。

@implementation MyLocationViewController {
GMSMapView *mapView_;
BOOL firstLocationUpdate_;
}

- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
longitude:151.2086
zoom:12];

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;

// Listen to the myLocation property of GMSMapView.
[mapView_ addObserver:self
forKeyPath:@"myLocation"
options:NSKeyValueObservingOptionNew
context:NULL];

self.view = mapView_;

// Ask for My Location data after the map has already been added to the UI.
dispatch_async(dispatch_get_main_queue(), ^{
mapView_.myLocationEnabled = YES;
});
}

- (void)dealloc {
[mapView_ removeObserver:self
forKeyPath:@"myLocation"
context:NULL];
}

#pragma mark - KVO updates

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (!firstLocationUpdate_) {
// If the first location update has not yet been recieved, then jump to that
// location.
firstLocationUpdate_ = YES;
CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
mapView_.camera = [GMSCameraPosition cameraWithTarget:location.coordinate
zoom:14];
}
}

@end

关于ios - 如何在 google sdk ios 中移动 gmsmapview 上的标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35036927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com