从MYSQL Point转换为Swift CLLocationCoordinate2D

问题描述:

I'm working on an application which retrieves locations from a MYSQL database as a Point type. One of the parameters to create a custom object is a CLLocationCoordinate2D. I've been unsuccessful in figuring out how the Point type works after it was JSON encoded from my server. I haven't been able to find any helpful documentation on what is returned or a way to convert from a MYSQL point to a Swift CLLocationCoordinate2D and was wondering if anyone else has had experience with this. Thanks

我正在开发一个应用程序,它从MYSQL数据库中检索位置作为Point类型。 创建自定义对象的参数之一是CLLocationCoordinate2D。 从我的服务器编码JSON后,我一直未能弄清楚Point类型是如何工作的。 我无法找到有关返回内容的任何有用文档或从MYSQL转换为Swift CLLocationCoordinate2D的方法,并且想知道其他人是否有过这方面的经验。 谢谢 p> div>

After many hours of searching, I have a solution that is working. Not sure if it's the best way, but it works.

Since MYSQL Point is store as (longitude latitude) (NO COMMA), I was able to issue a select statement

SELECT X(Column Name), Y(Column Name) from TABLE_NAME 

which in return gave me each of the values. From there, I used

(jsonElement as! NSString).doubleValue 

to create CLLocationDegrees for the points, which are needed in order to create a CLLocationCoordinate2D. If anyone else has found a better or more efficient solution, I would love to hear. Thanks