【发布时间】:2014-02-25 16:09:03
【问题描述】:
我正在尝试运行基本的 iOS 演示 SDK 代码。我已经创建了 API 密钥,它加载正常。 尽管我已将代码从 viewDidLoad 转移到 loadView,但效果仍然存在。见以下代码
-(void)loadView{
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
_mapView.myLocationEnabled = YES;
self.view = _mapView;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = _mapView;
}
相机已创建,但执行此行时
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
抛出一个带有描述的 NSException -> -[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance。
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[GMSMapView animateToCameraPosition:]: 无法识别的选择器发送到实例 0x14dbb870' * 第一次抛出调用栈:(0x2f462f4b 0x39cd96af 0x2f4668e7 0x2f4651cb 0x2f3b44d8 0x4cebe9 0x4cd78f 0x4ccc41 0x4ccb3d 0x21ced5 0x31bda1bd 0x31bda139 0x1d4b27 0x1d4a83 0x1d51cd 0x31bda37b 0x31c850f1 0x31c85007 0x31c845e3 0x31c8430d 0x31c8407d 0x31c84015 0x31bd5da3 0x3185cc6b 0x3185847b 0x3185830d 0x31857d1f 0x31857b2f 0x31bce0c3 0x2f42e1cd 0x2f42bb71 0x2f42beb3 0x2f396c27 0x2f396a0b 0x34097283 0x31c3a049 0xf58b1 0x3a1e1ab7) libc++abi.dylib:终止于 NSException 类型的未捕获异常
【问题讨论】:
-
如果将 CGRectZero 更改为带有框架的正确 CGRect 会发生什么?
-
已经找到了解决方案(请看下面 -> 今天我会做标记)。不错的建议-没有任何运气就尝试过。同样的事情也发生了。 CGrectZero 在他们的示例中,所以我想可以使用。另一件事是,在文档示例中,他们在 ViewDidLoad 中将地图添加为 self.view,至于在示例中,地图被添加到 loadView 中(我猜它负责加载视图更好)。
标签: ios google-maps google-maps-sdk-ios