如何使用Core Data(iPhone)存储CLLocation? [英] How to store CLLocation using Core Data (iPhone)?

查看:121
本文介绍了如何使用Core Data(iPhone)存储CLLocation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试保存位置,然后使用Core Location,MapKit和Core Data框架在地图上检索位置。

I'm trying to save a location and retrieve the location on a map afterward using Core Location, MapKit and Core Data frameworks.

我所做的只是将实体命名为POI,并添加了其他几个属性,如纬度(双重类型),经度(双重类型)。

What I've done is I just made entity named POI and added properties such as latitude (double type), longitude (double type) with few others.

简单地说,我的应用程序使用两个NSNumbers保存POI。 (lat和long),但我觉得必须有一个更聪明的方式来存储CLLocation。

Simply put, my app saves POI with two NSNumbers. (lat and long) but I feel like there must be a smarter way to store CLLocation than that.

干杯。

推荐答案

你所做的是好的。您应该将核心数据中的纬度和经度保存为双精度。当需要再次获取信息时,从Core Data中获取双精度值,并使用 CLLocationCoordinate2DMake CLLocationCoordinate2D c>。没有内置的方法来存储位置,因此存储纬度和经度组件是很好的。

What you're doing is fine. You should save the latitude and longitude as doubles in Core Data. When you need to get the information again, get the doubles back from Core Data and construct a CLLocationCoordinate2D struct with a function like CLLocationCoordinate2DMake. There's no built in way to store a location, so storing the latitude and longitude components is fine.

如果你不对纬度或经度进行任何数学运算找到边框等),你可以将它们存储为字符串。浮点值和双精度值可能会稍微更改其值,导致比较操作失败。

If you're not doing any math operations on the latitude or longitude (finding bounding boxes etc) you could store them as strings. Floats and doubles can change their values slightly, making comparison operations fail.

这篇关于如何使用Core Data(iPhone)存储CLLocation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆