user1495988 user1495988 - 6 months ago 17
iOS Question

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?

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);

It will return me an error bad access.

Answer

Your problem is the format string in your NSLog

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

The %@ means it's expecting an obj-c object. You're passing it a CGFloat. You should replace this with %f or maybe %g (those both take a floating-point value but output slightly differently).

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