是否可以输入六十进制的纬度和经度

发布于 2024-11-19 14:29:57 字数 1310 浏览 2 评论 0原文

我想弄清楚你是否可以给出一个六十进制输入作为一个位置,就像你可以在android中给出一个十进制输入一样:

 // Decimal input
 double src_lat = 46.550952;
 double src_long = 15.651366;

 GeoPoint srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),
        (int) (src_long * 1E6));

所以我的问题如下 - 有没有办法输入六十进制 数字而不是十进制? 我的数据库中有六十进制数字,格式为“46.550952、15.651366 等”。 但是当我以小数形式输入它们时,它显然给了我在 Google 地图上的错误位置,这是一个问题。

如果有任何答案或发现,我将非常感激。

--- 编辑 ---

我刚刚放弃并创建了一个将六十进制转换为十进制的函数 =) 由于我得到的所有字符串(数字)都是 10 个字符长,我可以简单地对分钟进行子串并秒。

代码如下:

private double turnSexagesimalToDecimal(String number) {
    double sumDivMinutes = 0;
        String degree = number;

        String degrees = degree.substring(0, 2);

        String minutes = degree.substring(3, 5);

        String second1 = degree.substring(5, 7);
        String second2 = degree.substring(7);
        String seconds = second1 + "." + second2;

        double divideSeconds = Double.parseDouble(seconds) / 60;

        sumDivMinutes = (Double.parseDouble(minutes) + divideSeconds) / 60;

        sumDivMinutes = (double)Math.round(sumDivMinutes * 1000000) / 1000000;
        sumDivMinutes = sumDivMinutes + Double.parseDouble(degrees);

    return sumDivMinutes;
}

i am trying to figure out if you can give a sexagesimal input as a location , just like you can give a decimal input in android like this:

 // Decimal input
 double src_lat = 46.550952;
 double src_long = 15.651366;

 GeoPoint srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),
        (int) (src_long * 1E6));

so my question is as follows - is there a way to enter sexagesimal numbers and not decimal?
I have sexagesimal numbers in my database, in the form of "46.550952, 15.651366, etc."
but when i enter them as decimals it obviously gives me the wrong location on Google Maps , which is a problem.

I would be really gratefull for any answers or findings.

--- EDIT ---

I just gave up and made a function that turns sexagesimal into decimal =) Since all of the strings (numbers) i get are 10 chars long i can simply substring the minutes and seconds.

the code is below:

private double turnSexagesimalToDecimal(String number) {
    double sumDivMinutes = 0;
        String degree = number;

        String degrees = degree.substring(0, 2);

        String minutes = degree.substring(3, 5);

        String second1 = degree.substring(5, 7);
        String second2 = degree.substring(7);
        String seconds = second1 + "." + second2;

        double divideSeconds = Double.parseDouble(seconds) / 60;

        sumDivMinutes = (Double.parseDouble(minutes) + divideSeconds) / 60;

        sumDivMinutes = (double)Math.round(sumDivMinutes * 1000000) / 1000000;
        sumDivMinutes = sumDivMinutes + Double.parseDouble(degrees);

    return sumDivMinutes;
}

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

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

发布评论

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

评论(1

为什么不写一个函数来在两者之间进行转换呢?

double decimalToSexagecimal(double decimalDegrees) { 
    String dd = new String(decimalDegrees);
    String[] ddArr = dd.split(".");
    // .75/100 = 75, .75 * 60/100
    double sd = Double.valueOf(ddArr).doubleValue() * 60 / 100;
    return Double.valueOf(ddArr[0] + "." + sd);
}

sexagecimalToDecimal(double sexagecimalDegreees) { ... }

why not just write a function to convert between the two?

double decimalToSexagecimal(double decimalDegrees) { 
    String dd = new String(decimalDegrees);
    String[] ddArr = dd.split(".");
    // .75/100 = 75, .75 * 60/100
    double sd = Double.valueOf(ddArr).doubleValue() * 60 / 100;
    return Double.valueOf(ddArr[0] + "." + sd);
}

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