MKMapView(注释和位置)- iPhone 开发

发布于 2024-11-25 18:25:35 字数 123 浏览 1 评论 0原文

如何确定某个点的坐标? 在知道 1 个特定位置的坐标后,如何为其创建图钉?是否有必要为此创建一个新类?

前 PIN 码为:纬度 = 37.786996; 经度=-122.440100;

How can I determine the coordinates of a certain spot?
How can I create a pin for 1 specific location after knowing it's coordinates? Is creating a new class for that necessary?

ex- PIN to : latitude = 37.786996;
longitude = -122.440100;

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

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

发布评论

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

评论(2

梦在夏天 2024-12-02 18:25:35

要在给定坐标处添加基本图钉,iOS 4+中最简单的方法是使用预定义的MKPointAnnotation类(无需定义自己的类)并且调用addAnnotation:。

如果您因为需要一些自定义属性而需要定义自己的注释类,请不要使用 MapCallouts 示例应用中显示的类作为基础。它们给人一种错误的印象,即您需要为每个唯一的坐标定义一个单独的类。相反,创建一个实现 MKAnnotation 协议但具有可设置的坐标属性的类。

编辑:
MKPointAnnotation 的示例:

MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(33, 35);
annotation.title = @"Title";
annotation.subtitle = @"Subtitle";
[mapView addAnnotation:annotation];
[annotation release];

如果您需要在类中的其他方法中轻松访问注释,则可以将其改为 ivar。

To add a basic pin at a given coordinate, the simplest way in iOS 4+ is to use the pre-defined MKPointAnnotation class (no need to define your own class) and call addAnnotation:.

If you need to define your own annotation class because you need some custom properties, don't use the classes shown in the MapCallouts sample app as a basis. They give the false impression that you need to define a separate class for each unique coordinate. Instead, create a class that implements the MKAnnotation protocol but with a settable coordinate property.

Edit:
An example with MKPointAnnotation:

MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(33, 35);
annotation.title = @"Title";
annotation.subtitle = @"Subtitle";
[mapView addAnnotation:annotation];
[annotation release];

If you need to easily access the annotation in other methods in the class, you can make it an ivar instead.

沉溺在你眼里的海 2024-12-02 18:25:35

您实现一个支持 MKMapAnnotation 协议的对象。您可以使用“addAnnotation:”调用将该对象添加到 mkmapview 中。这将为您提供地图上的默认图钉。

如果您想自定义引脚,您需要实现 MKMapViewDelegate 协议以返回带有自定义图像的 MKAnnotationView。

You implement an object that supports the MKMapAnnotation protocol. This object you add to your mkmapview with the "addAnnotation:" call. This will give you the default pin on the map.

If you want to customize the pin you need to implement the MKMapViewDelegate protocol to return an MKAnnotationView with a custom image.

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