处理来自 XML feed 的注释

发布于 2024-11-25 17:38:21 字数 974 浏览 0 评论 0原文

大家好,

目前我正在从(有效的)XML feed 中读取位置。

<locations>
    <location>
        <title>Supercoop</title>
        <category>supermarkt</category>
        <adres>Something</adres>
        <latitude>52.8982342</latitude>
        <longitude>5.2449449</longitude>
    </location>

    <location>
        <title>Thuis</title>
        <category>home</category>
        <adres>Something</adres>
        <latitude>52.223482</latitude>
        <longitude>5.248282</longitude>
    </location>
</locations>

“此示例中没有真实数据”

我使用 TouchXML 进行解析,效果很好。

我的问题是:将此信息处理为 MKAnnotation 的首选方式是什么。

我考虑过创建一个对象,例如:MyLocation 并将其存储在那里,但我必须遍历很多 MyLocation 对象。

其次,我希望当我使用“calloutAccessoryControlTapped”方法时可以访问该对象/注释,这样当它转到详细视图时,我可以访问比注释中存储的更多信息。

我希望并认为你们能帮助我! 谢谢!

罗尔夫

Hee all,

At this moment i'm working on reading locations from a (valid) XML feed.

<locations>
    <location>
        <title>Supercoop</title>
        <category>supermarkt</category>
        <adres>Something</adres>
        <latitude>52.8982342</latitude>
        <longitude>5.2449449</longitude>
    </location>

    <location>
        <title>Thuis</title>
        <category>home</category>
        <adres>Something</adres>
        <latitude>52.223482</latitude>
        <longitude>5.248282</longitude>
    </location>
</locations>

"No real data in this example"

I use TouchXML for the parsing and that works fine.

My question is: what is the preferred way of processing this information to a MKAnnotation.

I thought about making an object, for example: MyLocation and store it there, but than i have to walk trough lots of MyLocation objects.

Secondly i want that object / annotation be accessible when i use the "calloutAccessoryControlTapped" method so i can access more information than is stored in the annotation when it goes to a detailview for example.

I hope and think you guys can help me out!
Thanks!

Rolf

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

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

发布评论

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

评论(1

慵挽 2024-12-02 17:38:21

不确定“必须遍历大量 MyLocation 对象”是什么意思,但不管怎样,您必须创建一个符合 MKAnnotation 协议的对象并将其添加到地图中。

您可以在解析每个位置时立即调用 addAnnotation,或者更好的方法是将注释添加到 NSMutableArray,然后调用 addAnnotations 将它们一次性添加到地图中。

如果您不想创建自己的类并且使用的是 iOS 4+,则可以使用预定义的 MKPointAnnotation 类。这为您提供了属性标题、副标题和坐标,因此您必须以某种方式将标题、类别和地址压缩到其中。

创建自己的实现 MKAnnotation 的类并添加自定义属性并不难。这比尝试将属性塞入 MKPointAnnotation 更好。但是,请勿使用 MapCallouts 示例应用程序中提供的示例(这意味着您必须为每个唯一坐标创建一个单独的类)。相反,创建一个可设置的坐标属性。

在 calloutAccessoryControlTapped 方法中,可以使用 view.annotation 访问注释对象,然后您可以将其转换为自定义类并轻松访问属性。

对于一些示例代码,请尝试以下其他答案:

  • 将数据存储在 MKAnnotation 中?
  • <一个href="https://stackoverflow.com/questions/5949598/how-to-store-information-lated-of-a-pin-in-mkpinannotation/5951298#5951298">如何在 MKPinAnnotation 中存储与 pin 相关的信息 < /一>
  • <一href="https://stackoverflow.com/questions/6011931/i-have-30-annotations-and-grinding-looking-for-a-simpler-way-to-code-this/6012238#6012238">我有30 个注释,并且还在不断增加。正在寻找一种更简单的编码方法?

Not sure what you mean by "have to walk through lots of MyLocation objects" but one way or the other, you have to create an object that conforms to the MKAnnotation protocol and add it to the map.

You can either immediately call addAnnotation as you parse each location or, probably better, add the annotations to an NSMutableArray and then call addAnnotations to add them to the map in one shot.

If you don't want to create your own class and you are using iOS 4+, you can use the pre-defined MKPointAnnotation class. That gives you the properties title, subtitle, and coordinate so you'd have to squeeze your title, category, and adres in there somehow.

It's not hard to create your own class that implements MKAnnotation and add your custom properties. This is better than trying to cram your properties into MKPointAnnotation. However, do not use the example provided in the MapCallouts sample app (it implies you have to create a separate class for each unique coordinate). Instead, create a settable coordinate property.

In the calloutAccessoryControlTapped method, the annotation object is accessible using view.annotation and then you can cast it to your custom class and access the properties easily.

For some sample code, try these other answers:

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