简体   繁体   English

如何获得坐标?

[英]how to get the coordinates out?

I'm trying to extract the x and y coordinates out from self.mapView.gps.currentPoint how can I do it? 我正在尝试从self.mapView.gps.currentPoint提取x和y坐标我该怎么办?

Here is what I have done so far: 这是我到目前为止所做的:

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

Results: 结果:

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]
]"]`

and if I use NSLog(@"Location2 : %@", self.mapView.gps.currentPoint.x); 如果我使用NSLog(@"Location2 : %@", self.mapView.gps.currentPoint.x); It will return me an error bad access. 它将返回错误访问错误。

Your problem is the format string in your NSLog 您的问题是NSLog的格式字符串

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

The %@ means it's expecting an obj-c object. %@表示它期待一个obj-c对象。 You're passing it a CGFloat . 你传递的是CGFloat You should replace this with %f or maybe %g (those both take a floating-point value but output slightly differently). 您应该将其替换为%f%g (这些都采用浮点值但输出略有不同)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM