如何获得坐标?

时间:2012-08-14 02:13:39

标签: iphone ios gps xcode4.3 arcgis

我正在尝试从self.mapView.gps.currentPoint中提取x和y坐标,我该怎么办?

这是我到目前为止所做的:

NSLog(@"Location1 : %@", self.mapView.gps.currentPoint);

结果:

Location1 : AGSMutablePoint: x = 29841.008687, y = 40101.841687, spatial reference: 
    [AGSSpatialReference: wkid = 0, wkt = "PROJCS["SVY21",
    GEOGCS[
        "SVY21[WGS84]",
        DATUM[
            "D_WGS_1984",
            SPHEROID["WGS_1984",6378137.0,298.257223563]
        ],
        PRIMEM["Greenwich",0.0],
        UNIT["Degree",0.0174532925199433]
    ],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["False_Easting",28001.642],
    PARAMETER["False_Northing",38744.572],
    PARAMETER["Central_Meridian",103.8333333333333],
    PARAMETER["Scale_Factor",1.0],
    PARAMETER["Latitude_Of_Origin",1.366666666666667],
    UNIT["Meter",1.0]
]"]`

如果我使用NSLog(@"Location2 : %@", self.mapView.gps.currentPoint.x); 它会给我一个错误的错误访问权。

1 个答案:

答案 0 :(得分:2)

您的问题是NSLog

中的格式字符串
NSLog(@"Location2 : %@", self.mapView.gps.currentPoint.x);

%@表示它期待一个obj-c对象。你传递的是CGFloat。您应该将其替换为%f%g(这两者都采用浮点值,但输出略有不同)。

NSLog(@"Location2 : %f", self.mapView.gps.currentPoint.x);