首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在地图上从sqlite查看引脚,我怎样才能使它更快?

在地图上从sqlite查看引脚,我怎样才能使它更快?
EN

Stack Overflow用户
提问于 2011-08-23 04:21:52
回答 2查看 383关注 0票数 1

我正在开发一个在地图上查看图钉的应用程序

该应用程序正在使用以下代码从SQLite数据库读取引脚:

代码语言:javascript
复制
- (void) readDB
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex:0];

    NSString *filename = @"places.db";
    NSString *filedocPath = [docDir stringByAppendingPathComponent:filename];

    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    success = [fileManager fileExistsAtPath:filedocPath];

    if(success == NO)
    {
        NSString *configPathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:filename];

        [fileManager copyItemAtPath:configPathFromApp toPath:filedocPath error:nil];
        [fileManager release];
    }

    FMDatabase* db = [FMDatabase databaseWithPath:filedocPath];
    if (![db open]) {
        NSLog(@"Could not open db.");
        return;
    }

    // kind of experimentalish.
    [db setShouldCacheStatements:YES];


/*read*/
    for(int i = 0; i <colNum; i++)
    {
        [poi_Infos addObject:[[NSMutableArray alloc] init]];
    }

    NSString *queryString=[NSString stringWithFormat:@"select Category as %@,* from Places",categoryName];
    FMResultSet *rs = [db executeQuery:queryString];
    while ([rs next])
    {
        // just print out what we've got in a number of formats.
        [ [poi_Infos objectAtIndex:0] addObject:[rs stringForColumn:@"Company Name"]];
        [ [poi_Infos objectAtIndex:1] addObject:[NSNumber numberWithDouble:[[rs stringForColumn:@"Latitude"] doubleValue]] ];
        [ [poi_Infos objectAtIndex:2] addObject:[NSNumber numberWithDouble:[[rs stringForColumn:@"Longitude"] doubleValue]] ];
    }
    [rs close];  

    [db close];

    //NSLog(@"%@,%@", [[poi_Infos objectAtIndex:0] objectAtIndex:0],[[poi_Infos objectAtIndex:1] objectAtIndex:0]);

}

- (void) displayLocalPOI
{
    CLLocationCoordinate2D CurrentLocation;

    CurrentLocation=map.userLocation.coordinate;



    //set the radius in km so that you will get the nearest location in that radius

    double radius=localSearchRadius;


    int num = [[poi_Infos objectAtIndex:0] count];
    for(int i = 0; i < num; i++)
    {
        double y = [[[poi_Infos objectAtIndex:1] objectAtIndex:i] doubleValue];
        double x = [[[poi_Infos objectAtIndex:2] objectAtIndex:i] doubleValue];

        if(y>=CurrentLocation.latitude-(radius/111)&&y<=CurrentLocation.latitude+(radius/111))
        {
            if(x>=CurrentLocation.longitude-(radius/111)&&x<=CurrentLocation.longitude+(radius/111))
            {

                CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(
                                                                          (CLLocationDegrees)y, 
                                                                          (CLLocationDegrees)x);

                NSString *title = [[poi_Infos objectAtIndex:1] objectAtIndex:i];

                UserAnnotation *userAnnotation = [[UserAnnotation alloc] initWithCoordinate:coord];
                userAnnotation.title = title;
                [self.mapAnnotations addObject:userAnnotation];

                [userAnnotation release];
            }
        }



    }



}

由于我有超过10,000品脱,这个应用程序的工作非常慢。

我的问题是:

1-有什么方法可以让这个过程更快吗?就像在处理它们之前只选择半径内最近位置的引脚一样?请提供代码。

2-如果我缩小了,我怎么能掉更多的引脚?

EN

Stack Overflow用户

发布于 2011-08-23 22:24:58

要做的第一件事是分析你的应用程序,找出瓶颈在哪里,结果可能会让你感到沮丧,如果你不这样做,你可能会花费大量时间追求很少或根本没有性能提升。

除此之外,这里有一个很有帮助的页面,提供了一些让SQLite尽可能快地工作的一般建议:

http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#intro

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7153137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档