简体   繁体   English

单击注释气泡时,应用程序崩溃

[英]Application Crashes when annotation bubble clicked

I am creating annotations from database. 我正在从数据库创建注释。 But when I click on annotation to show bubble application crashes. 但是,当我单击注释以显示气泡应用程序崩溃时。 But when I hardcode the coordinates and create placemarks on map the bubbles popup successfully. 但是,当我对坐标进行硬编码并在地图上创建地标时,气泡会成功弹出。 below is the code I am fetching from database and loading annotations. 以下是我从数据库中获取并加载注释的代码。

-(void) mapView:(MKMapView *)imnMapView didAddAnnotationViews:(NSArray *)views; -(void)mapView:(MKMapView *)imnMapView didAddAnnotationViews:(NSArray *)views; { {

    BOOL *regionSet=FALSE;


                while(sqlite3_step(compiledStatement) == SQLITE_ROW)
                {
                    CLLocationCoordinate2D userCoods1;
                    NSString *lat = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 3)];
                    NSString *longg = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 4)];
                    float fLat = [lat floatValue];
                    float fLong = [longg floatValue];


    userCoods1.latitude = (CLLocationDegrees)fLat;

    userCoods1.longitude = (CLLocationDegrees)fLong;

                    if(regionSet == FALSE)
                    {
                        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userCoods1,400000,500000);
                        [mapView setRegion:region animated:YES];
                        regionSet=TRUE;
                    }

                    NSString *siteName = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 1)];
                    NSString *siteAddress = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 2)];


                    ParkPlaceMark *placemark=[[ParkPlaceMark alloc] initWithCoordinate1:userCoods1 title:siteName subtitle:siteAddress atm:@"ATM"];
                    pDescription = @"ATM";

                    [mapView addAnnotation:placemark];
                    [placemark release];

                }

            }               

            sqlite3_finalize(compiledStatement);

        }   

} }

And When i just change the userCoords hardcoded and create three different placemarks the bubbles popup and works fine. 当我只是更改userCoords硬编码并创建三个不同的地标时,气泡弹出并可以正常工作。 Please help me getting out of this. 请帮助我摆脱困境。 thanks in advance. 提前致谢。

Why don't you save the latitude and longitude values as a decimal or as a float in the database? 为什么不将纬度和经度值另存为十进制或浮点数呢? It is way more easier to convert it. 转换它更容易。

Can you log the values, using NSLog, that are in lat and longg? 您可以使用NSLog记录lat和longg中的值吗? Are they converted and stored right in flat and flong? 它们是否整齐地转换和存储?

NSLog(@"String - Latitude: %@ Longitude: %@", lat, longg);
NSLog(@"Float  - Latitude: %f Longitude: %f", fLat, fLong);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM