使用Google API查找最近的地方

时间:2012-02-01 10:07:28

标签: iphone objective-c google-maps google-maps-api-3

我正在开发一个Iphone应用程序,我正在使用GoogleAPI在500米内找到最近的洗手间。但我想要做的是从距离当前位置较少的地方开始,找到排序模式中的位置。

感谢。

1 个答案:

答案 0 :(得分:1)

假设restroomLocationscoordinatesArrayuserLocation是用户当前位置,并且您知道如何使用CoreLocation框架来获取所有用户的当前位置。以下方法可以帮助您:

-(NSMutableArray *)getRelevantRestrooms:(NSArray *)restroomLocations withUsersLocation:(CLLocation *)myLocation{
    NSMutableArray *resultsArray=[[NSMutableArray alloc]init];

    for (CLLocation *location in restroomLocations) {
        if ([location distanceFromLocation:myLocation]<=500){
            [resultsArray addObject:location];
        }
    }

    return [resultsArray autorelease];
}