使用GoogleAPI查找最近的地点 [英] Finding nearest places using GoogleAPI
问题描述
我正在开发一个Iphone应用程序,使用GoogleAPI在500米范围内找到最近的卫生间。但我想做的事情是从距离当前位置较近的地方开始,以排序模式查找地点。
谢谢。
假设 restroomLocations
是 coordinatesArray
, userLocation
是用户当前的位置,并且您知道如何使用 CoreLocation
框架来获取所有用户的当前位置。下面的方法可以帮助你:
- (NSMutableArray *)getRelevantRestrooms:(NSArray *)restroomLocations withUsersLocation:(CLLocation *)myLocation {
NSMutableArray * resultsArray = [[NSMutableArray alloc] init];
$ b $ for(CLLocation * location in restroomLocations){
if([location distanceFromLocation:myLocation]< = 500){
[resultsArray addObject:location];
}
}
return [resultsArray autorelease];
}
I am developing an Iphone application in which i am using GoogleAPI to find the nearest Restrooms within 500 meters. But the thing i want to do is to find the places in sorted pattern starting from places whose distance is less from current location.
Thanks.
Assume restroomLocations
is the coordinatesArray
, userLocation
is the user current location, and that you know how to use the CoreLocation
framework to get all users' current location. The following method will help you:
-(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];
}
这篇关于使用GoogleAPI查找最近的地点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!