MKMapView(注释和位置)- iPhone 开发
如何确定某个点的坐标? 在知道 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要在给定坐标处添加基本图钉,iOS 4+中最简单的方法是使用预定义的
MKPointAnnotation
类(无需定义自己的类)并且调用addAnnotation:。如果您因为需要一些自定义属性而需要定义自己的注释类,请不要使用
MapCallouts
示例应用中显示的类作为基础。它们给人一种错误的印象,即您需要为每个唯一的坐标定义一个单独的类。相反,创建一个实现 MKAnnotation 协议但具有可设置的坐标属性的类。编辑:
MKPointAnnotation 的示例:
如果您需要在类中的其他方法中轻松访问注释,则可以将其改为 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 calladdAnnotation:
.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 theMKAnnotation
protocol but with a settablecoordinate
property.Edit:
An example with
MKPointAnnotation
:If you need to easily access the annotation in other methods in the class, you can make it an ivar instead.
您实现一个支持 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.