MapKit注释和用户位置 [英] MapKit Annotations and User location
问题描述
我跟着这个教程,使我的第一个应用程序:
I followed this tutorial to make my first app:
HTTP ://i$c$cblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/
我真的想知道如何在距离以便用户在表注释进行排序(最近的注释是餐桌上的第一个)怎么可能做到呢?
I would really like to know how to sort the annotations in the Table in order of distance to the user (the nearest annotation is the first one on the table) How is it possible to do that?
我知道我必须使用CLLocation找到用户的位置,但后来我也没办法。
I understand that I must use the CLLocation to find the user's location but then I have no idea.
可以在任何一个可以帮助我?
Could any one help me?
干杯,
感谢您提前为您的多AP preciated帮助,
Thank you in advance for your much appreciated help,
编辑:我补充细节:
的数据不是在一个数组,它在RootViewController.m实现以这种形式:
the data is not in an array, it is implemented in RootViewController.m in this form:
-(void)loadOurAnnotations
{
CLLocationCoordinate2D workingCoordinate;
workingCoordinate.latitude = 40.763856;
workingCoordinate.longitude = -73.973034;
iCodeBlogAnnotation *appleStore1 = [[iCodeBlogAnnotation alloc]
initWithCoordinate:workingCoordinate];
[appleStore1 setTitle:@"Apple Store 5th Ave."];
[appleStore1 setSubtitle:@"Apple's Flagship Store"];
[appleStore1 setAnnotationType:iCodeBlogAnnotationTypeApple];
[mapView addAnnotation:appleStore1];
...等等。这怎么可能做到这一点呢?
... and so on. How is it possible to do it then?
您可以在这里找到源$ C $ C:
You can find the source code here:
I codeblog.com /可湿性粉剂内容/上传/ 2009/09 / I codeMap.zip
icodeblog.com/wp-content/uploads/2009/09/iCodeMap.zip
teddafan
推荐答案
在一个 CLLocation
您可以使用
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
从另一计算的对象的距离。在这种情况下,这将presumably是用户的当前位置。
to calculate the distance of an object from another. In this case, it would presumably be the user's current location.
如果该数据是在的NSArray
您可以使用 sortedArrayUsingFunction
调用调用此方法的辅助函数。
If the data is in an NSArray
you can use sortedArrayUsingFunction
to call a helper function that calls this method.
这篇关于MapKit注释和用户位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!