首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法对对象执行循环操作

无法对对象执行循环操作
EN

Stack Overflow用户
提问于 2014-12-06 18:27:47
回答 2查看 60关注 0票数 0

我正在尝试创建这个http://www.ibm.com/developerworks/library/j-coordconvert/ -Military网格参考系统的可视化网格。我有到UTM的经纬度,也有到MGRS...which ar的经度。

17 T 330649 4689666

17TLG3064989666

但是,当从MGRS转到纬度时,我得到以下信息:[D@18e3f02a

代码语言:javascript
复制
public class CoordinateConversion {
    public static void main(String args[]) {

        CoordinateConversion test = new CoordinateConversion();
        CoordinateConversion test2 = new CoordinateConversion();
        test.latLon2UTM(35.58, 82.56);
        System.out.println(test.latLon2UTM(42.340837, -83.055821));
        System.out.println();
        test2.latLon2UTM(35.58, 82.56);
        System.out.println(test2.latLon2MGRUTM(42.340837, -83.055821));

        CoordinateConversion test3 = new CoordinateConversion();
        test3.latLon2UTM(35.58, 82.56);
        //System.out.print(test3.mgrutm2LatLong(42.340837, -83.055821));
        //System.out.println(test3.mgrutm2LatLong("02CNR0634657742"));


        MGRUTM2LatLon mg = new MGRUTM2LatLon();
        //mg.convertMGRUTMToLatLong("02CNR0634657742");
        String MGRUTM = "17TLG3064989666";
        System.out.println(mg.convertMGRUTMToLatLong(MGRUTM));
        //for loop to be developed

    }

    public double[] utm2LatLon(String UTM) {
        UTM2LatLon c = new UTM2LatLon();
        return c.convertUTMToLatLong(UTM);
    }

    public double[] mgrutm2LatLon(String MGRUTM) {
        MGRUTM2LatLon c = new MGRUTM2LatLon();
        return c.convertMGRUTMToLatLong(MGRUTM);
    }
}

来自这个班:

代码语言:javascript
复制
public double[] convertMGRUTMToLatLong(String mgrutm) {
    double[] latlon = {0.0, 0.0};
    // 02CNR0634657742
    int zone = Integer.parseInt(mgrutm.substring(0, 2));
    String latZone = mgrutm.substring(2, 3);

    String digraph1 = mgrutm.substring(3, 4);
    String digraph2 = mgrutm.substring(4, 5);
    easting = Double.parseDouble(mgrutm.substring(5, 10));
    northing = Double.parseDouble(mgrutm.substring(10, 15));

    LatZones lz = new LatZones();
    double latZoneDegree = lz.getLatZoneDegree(latZone);

    double a1 = latZoneDegree * 40000000 / 360.0;
    double a2 = 2000000 * Math.floor(a1 / 2000000.0);

    Digraphs digraphs = new Digraphs();

    double digraph2Index = digraphs.getDigraph2Index(digraph2);

    double startindexEquator = 1;
    if ((1 + zone % 2) == 1) {
        startindexEquator = 6;
    }

    double a3 = a2 + (digraph2Index - startindexEquator) * 100000;
    if (a3 <= 0) {
        a3 = 10000000 + a3;
    }
    northing = a3 + northing;

    zoneCM = -183 + 6 * zone;
    double digraph1Index = digraphs.getDigraph1Index(digraph1);
    int a5 = 1 + zone % 3;
    double[] a6 = {16, 0, 8};
    double a7 = 100000 * (digraph1Index - a6[a5 - 1]);
    easting = easting + a7;

    setVariables();

    double latitude = 0;
    latitude = 180 * (phi1 - fact1 * (fact2 + fact3 + fact4)) / Math.PI;

    if (latZoneDegree < 0) {
        latitude = 90 - latitude;
    }

    double d = _a2 * 180 / Math.PI;
    double longitude = zoneCM - d;

    if (getHemisphere(latZone).equals("S")) {
        latitude = -latitude;
    }

    latlon[0] = latitude;
    latlon[1] = longitude;
    return latlon;
}

我正在努力不进入一个大型图书馆,在那里我将不得不学习一些可能很费时的东西。

所以我试图绕圈,所以我向东(向东)和向北(向北),无法越过我有一个点--纬度/经度。

希望我已经清楚地提出了我的问题,而没有说得太多。

任何帮助都将不胜感激。

谢谢,-Terry

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-06 18:54:20

在方法convertMGRUTMToLatLong(String s)中,您将返回一个数组latlon (即一个对象)。它返回它的哈希码,这可能是你不想要的。要打印数组值。所以在你的主要方法中,你替换了下面的一行;

代码语言:javascript
复制
System.out.println(mg.convertMGRUTMToLatLong(MGRUTM));

使用

代码语言:javascript
复制
    double[] a = mg.convertMGRUTMToLatLong(MGRUTM) ;
System.out.println(a[0]+" " + a[1] );

希望这能帮上忙!

票数 0
EN

Stack Overflow用户

发布于 2014-12-06 18:53:02

convertMGRUTMToLatLong()的结果是一个double数组,在默认情况下,数组以相当不可读的格式转换为字符串。这就是[D@18e3f02a的来源。尝试System.out.println(Arrays.toString(mg.convertMGRUTMToLatLong(MGRUTM)));,您将获得一个更易读的输出。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27334955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档