gpt4 book ai didi

iOS Google maps sdk - 使用 subview 而不是主视图时标记不指向

转载 作者:行者123 更新时间:2023-11-28 19:01:14 25 4
gpt4 key购买 nike

尝试显示一个简单的谷歌地图,在位置“position”处带有标记。

如果 mapview_ 显示在类 GMSMapView 的 self.view( Controller 的默认 View )而不是 gmapsView(self.view 的 subview )中,则一切正常。

我已经浏览了一些关于 SO 的帖子,但无法解决问题。在界面生成器中,gmapsview 类设置为 GMSMapView。

相机位置设置

 CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
37.778376,
-122.409853);
CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:position.latitude longitude:position.longitude];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:position.coordinate.latitude
longitude:position.coordinate.longitude
zoom:13];

map 设置

mapView_ = [GMSMapView mapWithFrame:self.gmapsView.frame camera:camera];
mapView_.delegate = self;
self.gmapsView.camera = camera; //gmapsView is a view of class GMSMapView

CGRect rect = self.locationBlockView.frame;

self.gmapsView.delegate = self; //Added to check whether it works
self.gmapsView = mapView_;

设置标记

GMSMarker *marker = [GMSMarker markerWithPosition:position]; //Adding Marker
marker.map = mapView_;
[mapView_ animateToLocation:position.coordinate];

最佳答案

重新初始化 map 导致了这个问题。一旦它被删除,它就解决了这个问题。但是重新初始化 GMSMapView 是导致问题的原因吗?这是一件荒谬的事情,但它解决了这个问题。

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
12.778376,
-122.409853);
currentLocation = [[CLLocation alloc] initWithLatitude:position.latitude longitude:position.longitude];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:eventLocation.coordinate.latitude
longitude:eventLocation.coordinate.longitude
zoom:13];
//[self.gmapsView removeFromSuperview];//removing the subview
//self.gmapsView = [GMSMapView mapWithFrame:self.gmapsView.frame camera:camera];
//self.gmapsView.delegate = self;

//self.gmapsView = self.gmapsView; //set map

// [self.view addSubview:self.gmapsView];//Adding back did the magic
self.gmapsView.delegate = self; //set delegate
self.gmapsView.camera = camera; //set camera

GMSMarker *marker = [GMSMarker markerWithPosition:position]; //Adding Marker
marker.map = self.gmapsView;
[self.gmapsView animateToLocation:currentLocation.coordinate];

关于iOS Google maps sdk - 使用 subview 而不是主视图时标记不指向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25352620/

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