简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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