从地图视图中选择位置

发布于 2024-12-29 21:12:03 字数 156 浏览 0 评论 0原文

我正在考虑一个应用程序,用户可以在 iPhone 应用程序上选择一个位置。我用谷歌搜索了一下,没有找到任何有用的东西。

我的问题是,是否可以让用户使用 MapKit/CLLocation 从 iPhone 应用程序中选择位置?如果是,请帮助我我应该从哪里开始。

谢谢

I was thinking of an application where user could select a location on an iphone app. I have googled it and didn't find anything useful.

My question is, is it possible to let the user select a location from an iphone app using MapKit/CLLocation? If yes, please help me where should i start.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

梦里寻她 2025-01-05 21:12:03

您可以向地图添加长按手势识别器:

UILongPressGestureRecognizer* lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.5;
lpgr.delegate = self;
[self.map addGestureRecognizer:lpgr];
[lpgr release];

在句柄长按方法中获取 CLLocationColute2D:

- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
    /*
     Only handle state as the touches began
     set the location of the annotation
     */

    CLLocationCoordinate2D coordinate = [self.map convertPoint:[gestureRecognizer locationInView:self.map] toCoordinateFromView:self.map];

    [self.map setCenterCoordinate:coordinate animated:YES];

  // Do anything else with the coordinate as you see fit in your application

   }
}

You can add a long press gesture recognizer to the map:

UILongPressGestureRecognizer* lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.5;
lpgr.delegate = self;
[self.map addGestureRecognizer:lpgr];
[lpgr release];

In the handle long press method get the CLLocationCordinate2D:

- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
    /*
     Only handle state as the touches began
     set the location of the annotation
     */

    CLLocationCoordinate2D coordinate = [self.map convertPoint:[gestureRecognizer locationInView:self.map] toCoordinateFromView:self.map];

    [self.map setCenterCoordinate:coordinate animated:YES];

  // Do anything else with the coordinate as you see fit in your application

   }
}
雨巷深深 2025-01-05 21:12:03

看看这个答案。答案不仅告诉你如何获取坐标,还告诉你如何在地图上放置图钉(注释)。

Take a look at this SO answer. The answer tells you not only how to get the coordinate, but also how to put a pin (annotation) on the map.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文