ios - 在 iOS 9 中使用 GMSPlace Picker 时应用程序崩溃

标签 ios ios9 google-maps-sdk-ios gmsplace

当用户未从选取器 View 中选择任何位置并按返回按钮时,GMSPlacePicker 会崩溃。

错误:

-[UIWindow _shouldAnimatePropertyWithKey:]: message sent to deallocated instance

代码:

- (void)findNearByPlace :(CLLocationCoordinate2D)center {


CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001,
                                                              center.longitude + 0.001);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001,
                                                              center.longitude - 0.001);
GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
                                                                     coordinate:southWest];
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
_placePicker = [[GMSPlacePicker alloc] initWithConfig:config];

[_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {
    if (error != nil) {
        NSLog(@"Pick Place error %@", [error localizedDescription]);
        return;
    }
    if (place != nil) {
        NSLog(@"Place name:%@",place.formattedAddress);
        placeName = place.name;
        placeAddress = place.formattedAddress;
        //hide previous marker
        self.mapMarker.map = nil;
        self.locaitonTitle = place.name;
        self.locationAddress = place.formattedAddress;
        self.mapMarker = [GMSMarker markerWithPosition:place.coordinate];
        self.mapMarker.icon = [UIImage imageNamed:@"ic_ellipse_black.png"];
        mapLattitude = place.coordinate.latitude;
        mapLongitude = place.coordinate.longitude;
        self.mapMarker.draggable = YES;
        markerTag = @"2";
        markerDefault = @"default";
        self.mapMarker.userData = @{};
        self.mapMarker.map = self.mapView_;
        [self showLocationPopUp:placeName address:placeAddress withCoord:place.coordinate];
        //[self showLocationFoundView];
    } else {

        [self addOwnLocation : longPressCoord];
        NSLog(@"No Place is selected yet");
    }
}];

有什么解决办法吗?

最佳答案

我们遇到了同样的问题。我们的解决方案是通过隐藏导航栏来禁用 Back 导航按钮。

objective-C :

[placePicker pickPlaceWithCallback:^(GMSPlace * __nullable result, NSError * __nullable error) {
    //DO SOMETHING
}];

//Hide the navigation bar
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    UINavigationController *rootViewController = (UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
    rootViewController.navigationBarHidden = true;
});

swift :

placePicker.pickPlaceWithCallback({ (place: GMSPlace?, error: NSError?) -> Void in
    //DO SOMETHING     
})

//Hide the navigation bar
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue(), { () -> Void in
     let rootViewController = UIApplication.sharedApplication().keyWindow?.rootViewController
     (rootViewController as! UINavigationController).navigationBarHidden = true
})

关于ios - 在 iOS 9 中使用 GMSPlace Picker 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32816212/

相关文章:

ios - 如何使用 soap Web 服务 ios 的字典将值存储在数组中

ios - 即使在导入 MapKit 后仍使用未声明的类型 'MKMapView'

xcode - 从 Swift 1.2 - 2.0 更新 tableView 代码

iOS 胖二进制文件 : should every arch include bitcode?

swift - 如何使用 Swift 在我的应用程序中显示 App Store 搜索的内容

ios - 动态添加新的语言字符串文件以在 iOS 中进行本地化

ios - 如何限制在 Swift 的 Algolia 索引中可搜索的字段?

ios - iOS 版 Google map 中的自定义用户位置点 (GMSMapview)

iOS 添加具有连线现象结果的 GMSPolylines

iphone - 如何在iPhone中的Google Map sdk中获取当前位置