gpt4 book ai didi

java - 如何处理像 50°3 2'20.548\\\"N"这样的坐标?

转载 作者:行者123 更新时间:2023-12-02 09:22:28 34 4
gpt4 key购买 nike

我想在我的 Android 项目中实现 map 。我已经准备好 map 、坐标和所有方法,但我发现我不知道如何处理收到的坐标格式:

50°32'20.548\\"N"

Android Studio 需要这样的双格式:-33.852, 151.211……我不知道如何转换它。有没有人处理过类似的问题并可以帮助我?

谢谢:)

我必须使用的坐标(无法更改它们):

{
"monumentid1": {
"name": "Bečov nad Teplou - Zámek",
"gpsx": "50°5'8.145\\\"N",
"gpsy": "12°50'23.468\\\"E"
},
"monumentid2": {
"name": "Benešov nad Ploučnicí - Zámek ",
"gpsx": "50°44'32.727\\\"N",
"gpsy": "14°18'39.412\\\"E"
},
"monumentid3": {
"name": "Bezděz - Hrad",
"gpsx": "50°32'20.548\\\"N",
"gpsy": "14°43'11.607\\\"E"

最佳答案

Location类有一个静态方法来执行 DMS 字符串转换(到 double ) - 但首先需要调整字符串以匹配“DD:MM:SS.SSSS”的可接受格式。转换后,符号需要针对半球进行调整:

public class HelloWorld
{
public static void main(String[] args)
{
// The triple backslash is data author's attempt to escape the double-quote.
String s = "50°32'20.548\\\"N";

// Get rid of any residual backslashes
s = s.replace("\\","");

// split string into constituent parts using apparent separators
String[] dms = s.split("[°'\"]");

// form 'newS' which complies with Location.FORMAT_SECONDS
String newS = dms[0]+":"+dms[1]+":"+dms[2];

// and grab hemisphere (to implement sign)
String hemi = dms[3];

double coord = Location.convert(newS);
if (hemi.compareTo("W") == 0 || hemi.compareTo("S") == 0) {
coord = -coord;
}
}

}

关于java - 如何处理像 50°3 2'20.548\\\"N"这样的坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58592979/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com