MapKit 注释和用户位置

发布于 2024-08-31 15:00:35 字数 1085 浏览 1 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潜移默化 2024-09-07 15:00:35

CLLocation上,您可以用来

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

计算一个对象与另一个对象的距离。在这种情况下,它可能是用户的当前位置。

如果数据位于 NSArray 中,您可以使用 sortedArrayUsingFunction 来调用调用此方法的辅助函数。

On a CLLocation you can use

- (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.

If the data is in an NSArray you can use sortedArrayUsingFunction to call a helper function that calls this method.

七婞 2024-09-07 15:00:35

循环遍历 CLLocations 并找到它们与您当前位置之间的距离。

然后使用您自己的排序算法对数组中的距离进行排序。

for (CLLocation *loc in locations) {
  [distances addobject:[currentLocation distanceFromLocation:loc]];
}
[distances sort]; /* Own sorting algorithm */
[yourTable reloadData];

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.

for (CLLocation *loc in locations) {
  [distances addobject:[currentLocation distanceFromLocation:loc]];
}
[distances sort]; /* Own sorting algorithm */
[yourTable reloadData];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文