ios - 如何从iOS中的位置数组中找到5m到10m范围内的最近位置?
<p><p>这是我的代码,我希望距离当前位置最近的位置在 10 米范围内,并且我想添加所有最近的位置以及此人的详细信息作为响应还添加 array.thanks</p>
<p>这是我来自服务器的响应</p>
<pre><code>{
born = 0;
completed = 0;
"emergency_id" = "-1";
eyes = "";
feet = 0;
"first_name" = Neil;
glasses = No;
hair = "";
inch = 0;
language = "<null>";
"last_name" = Ferris;
latitude = "30.1456987";
longitude = "76.69916";
marks = "";
"member_id" = 21634;
picture = "";
"profile_id" = 5826;
type = 1;
updated = "2015-09-16 06:32:08";
weight = 0;
}
</code></pre>
<p>像上面一样,我从服务器获得了 5000 个用户,在我通过当前位置以 10 米的距离进行过滤后,我需要在表格 View 中显示在 10 米以下范围内的列表</p>
<pre><code>- (void)getdata
{
NSString * apiURLStr =;
NSString *outputStr = encoding:NSUTF8StringEncoding error:nil];
NSDictionary *response;
if (outputStr == nil)
{
return;
}
NSData* data = ;
NSError *error;
response = ;
NSMutableArray *array=[init];
CLLocation *closestLocation = nil;
for (NSDictionary *dict in response)
{
NSString *latitude=;
NSString *longitude=;
CLLocation *location = [ initWithLatitude:latitude.doubleValue
longitude:longitude.doubleValue];
;
}
CLLocationDistance closestLocationDistance = DBL_MIN;
for (CLLocation *location in array)
{
if (!closestLocation) {
closestLocation = location;
closestLocationDistance = ;
continue;
}
CLLocationDistance currentDistance = ;
if (currentDistance < closestLocationDistance)
{
closestLocation = location;
closestLocationDistance = currentDistance;
}
}
NSLog(@"closestLocation %@",closestLocation.description);
NSLog(@"closestLocationDistance %f", closestLocationDistance);
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><blockquote>
<p>thanks for answer bro,but i want list of closest locations in below 10 meters range.</p>
</blockquote>
<pre><code>NSMutableArray *locationsInRange = ;
for (CLLocation *location in array)
{
CLLocationDistance currentDistance = ;
if (currentDistance < 10)
{
;
}
}
NSLog(@"locations in 10 metters %@",locationsInRange.description);
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何从iOS中的位置数组中找到5m到10m范围内的最近位置?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32758916/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32758916/
</a>
</p>
页:
[1]