在 Java 中处理 GPS 数据
我正在使用 GPS Web 服务,该服务以以下格式检索信息(出于隐私原因,数字略有变化,但格式不变):
X: 32 14 08.47S
Y: 140 17 12.82E
我需要做的是将这些转换为十进制坐标 (xx.xxxxxxxxx, xx) .xxxxxxxxx)。是否有任何简单的 Java 代码片段可以完成此任务?如果没有,我很乐意查看解释如何用不同语言实现此目的的资源。
I'm using a GPS web service that is retrieving information in the following format (numbers changed up a bit for privacy reasons but format is unchanged):
X: 32 14 08.47S
Y: 140 17 12.82E
What I need to do is convert these to decimal co-ordinates (xx.xxxxxxxxx, xx.xxxxxxxxx). Are there any simple snippets of Java code that can do this task? If not, I'm happy to look at resources that explain how to achieve this in a different language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果保证度、分和秒被分隔一个空格,您可以做一些简单的事情,这样
您就可以使用
Double.parseDouble()
标记后面的那些[0] 获取数字度、分和秒,然后将它们组合起来得到十进制。当然,对于tokens[3]
您必须在进行解析之前去掉最后的 N/S/E/W 字符。另一种更优雅的可能性可能是利用
MessageFormat
及其子类可用于解析给定格式的字符串以及格式化此类字符串。If the degrees, minutes, and seconds are guaranteed to be separated a single space you could do something as simple as
That will leave you with
You could then
Double.parseDouble()
the ones aftertokens[0]
to get the numeric degrees, minutes, and seconds which you would then combine to get the decimal degrees. Of course fortokens[3]
you'd have to strip off the final N/S/E/W character before doing the parse.Another more elegant possibility might be to take advantage of the fact that instances of
MessageFormat
and its subclasses can be use for parsing a string of a given format as well as formatting such a string.