MapKit 注释和用户位置
我按照本教程制作了我的第一个应用程序:
http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/
我真的很想知道如何对按到用户距离的顺序排列的表格(最近的注释是表格上的第一个注释)怎么可能做到这一点?
我知道我必须使用 CLLocation 来查找用户的位置,但我不知道。
有人可以帮助我吗?
干杯,
提前感谢您非常感谢的帮助,
编辑:我添加了详细信息:
数据不在数组中,它以这种形式在 RootViewController.m 中实现:
-(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];
...等等。那怎么可能呢?
找到源代码:
icodeblog.com/wp-content/uploads/2009/09/iCodeMap.zip
您可以在这里
I followed this tutorial to make my first app:
http://icodeblog.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?
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?
Cheers,
Thank you in advance for your much appreciated help,
EDIT: I've added details:
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?
You can find the source code here:
icodeblog.com/wp-content/uploads/2009/09/iCodeMap.zip
teddafan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
CLLocation
上,您可以用来计算一个对象与另一个对象的距离。在这种情况下,它可能是用户的当前位置。
如果数据位于
NSArray
中,您可以使用sortedArrayUsingFunction
来调用调用此方法的辅助函数。On a
CLLocation
you can useto calculate the distance of an object from another. In this case, it would presumably be the user's current location.
If the data is in an
NSArray
you can usesortedArrayUsingFunction
to call a helper function that calls this method.循环遍历 CLLocations 并找到它们与您当前位置之间的距离。
然后使用您自己的排序算法对数组中的距离进行排序。
Loop through the CLLocations and find the distance between them and your current location.
Then use your own sorting algorithm to sort the distances you are having in an array.