MapKit 注释和用户位置 [英] MapKit Annotations and User location

查看:41
本文介绍了MapKit 注释和用户位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本教程制作了我的第一个应用程序:

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?

我知道我必须使用 CLLocation 来查找用户的位置,但我不知道.

I understand that I must use the CLLocation to find the user's location but then I have no idea.

有人可以帮我吗?

干杯,

预先感谢您的帮助,

我添加了详细信息:

数据不是数组,它在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?

您可以在此处找到源代码:

You can find the source code here:

icodeblog.com/wp-content/uploads/2009/09/iCodeMap.zip

icodeblog.com/wp-content/uploads/2009/09/iCodeMap.zip

泰达范

推荐答案

CLLocation 上你可以使用

- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location

计算一个物体与另一个物体的距离.在这种情况下,它大概是用户的当前位置.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆