Google地图无法加载,导致整个应用崩溃

时间:2016-01-12 19:41:25

标签: ios swift google-maps

我还没有解决这个问题。

我曾在几个项目中使用谷歌地图,包括Objective C和Swift 2以及iOS 9.我使用可可豆荚安装它并且它工作得很好但是现在,在这个应用程序中,我和#9;我还使用解析和四方API(不确定是否与它有任何关系)地图视图甚至无法加载,当我尝试时应用程序崩溃。

这是我得到的错误......

- [GMSMapView animateToCameraPosition:]:无法识别的选择器发送到实例0x7fe51cb3bfb0

它在设置地图视图框架的行上断开,我也尝试添加Obj-C链接器标记(我听说过这可能是一个可能的解决方案)但是这给了我32个不同的错误本身。

任何人都可以帮忙吗?万分感谢。

1 个答案:

答案 0 :(得分:0)

不能说我在Swift中有使用谷歌地图的经验,但这里有一些Obj-C代码可以解决。首先确保您的GMSMapView委托设置为self,并且您要在viewDidLoad中设置约束。我在各个地方跑了这个:

- (void)setBounds
{
CLLocationCoordinate2D coordinate = [self.currentLocation coordinate];

CGFloat coordinateDifference = 0.002;

CGFloat firstLatitude = coordinate.latitude;
firstLatitude += coordinateDifference;

CGFloat firstLongitude = coordinate.longitude;
firstLongitude += coordinateDifference;

CLLocationDegrees topLat = firstLatitude;
CLLocationDegrees topLon = firstLongitude;
CLLocationCoordinate2D northEastCoordinate = CLLocationCoordinate2DMake(topLat, topLon);

CGFloat secondLatitude = coordinate.latitude;
secondLatitude -= coordinateDifference;

CGFloat secondLongitude = coordinate.longitude;
secondLongitude -= coordinateDifference;

CLLocationDegrees botLat = secondLatitude;
CLLocationDegrees botLon = secondLongitude;
CLLocationCoordinate2D southWestCoordinate = CLLocationCoordinate2DMake(botLat, botLon);

self.bounds = [[GMSCoordinateBounds alloc] init];
self.bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:northEastCoordinate coordinate:southWestCoordinate];
}

- (void)createMap
{
CLLocationCoordinate2D coordinate = [self.currentLocation coordinate];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitude zoom:17];

CGFloat h = self.topLayoutGuide.length;
CGRect rect = CGRectMake(0, h, self.view.bounds.size.width, self.view.bounds.size.height - self.navigationController.navigationBar.frame.size.height - self.postSongButton.frame.size.height - 20);
self.mapView = [GMSMapView mapWithFrame:rect camera:camera];

[self.view insertSubview:self.mapView atIndex:0];
}