【发布时间】:2014-08-17 19:00:19
【问题描述】:
尝试在“位置”位置显示带有标记的简单 Google 地图。
如果 mapview_ 显示在 self.view(控制器的默认视图)而不是 GMSMapView 类的 gmapsView(self.view 的子视图)中,则一切正常。
我浏览了 SO 上的一些帖子,但无法解决问题。 在 Interface builder 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];
地图设置
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];
【问题讨论】:
-
我不明白你我害怕。你想要什么,什么有效,什么无效?
-
@Daij-Djan 1. 地图和标记正在默认视图中加载。 2.地图加载在子视图中,但不显示标记。
-
gmapsView 属于“GMSMapView”类。类在 IB 中设置并在控制器中有链接。
-
那你为什么要分配初始化一个新实例?
-
是的,这就是错误!最初尝试由 developer.google 提供的示例代码,后来根据我的需要进行了修改。我刚刚尝试删除实例化并从中提琴它的工作。但从逻辑上讲,即使重新实例化它也应该可以正常工作?在正常情况下,当通过重新初始化访问 UIView 时,它为什么会在这里失败?
标签: ios objective-c google-maps ios7 google-maps-sdk-ios