7

How can I convert CLLocation or CLLocationCoordinate2D to CGPoint. I have seen

CGPoint point = [mapView convertCoordinate:myCoordinates toPointToView:self.view];

But I don't need to use mapView in my case. I tried googling, but didn't come across anything helpful.

Edit: I need to convert the geographic coordinates to iPad's screen coordinate as in Convert decimal latitude/longitude coordinates to iPad screen coordinates. I am trying to draw line/path based on the converted coordinate values.

Is there a direct way to do it, or do I need to write an algorithm to do the same.

Community
  • 1
  • 1
Xavi Valero
  • 2,047
  • 7
  • 42
  • 80
  • If you don't need to use mapView then why do you need to convert coordinate to CGPoint? – Geek Jun 21 '13 at 11:47
  • No other way except using a map view. – Ishank Jun 21 '13 at 11:49
  • I get current coordinates from `- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations`. Need to draw a path based on that on a view. No maps here. – Xavi Valero Jun 21 '13 at 11:49
  • check this out:-http://stackoverflow.com/questions/16124171/convert-decimal-latitude-longitude-coordinates-to-ipad-screen-coordinates – Nitin Gohel Jun 21 '13 at 11:56
  • I'm not sure that , Possible to get it without MapView..? . But I'll give some idea but this should be **STUPID idea** - Load the Mapview and HIDE It and get the CGPoint by using the Method You mentioned ... – Kumar KL Jun 21 '13 at 12:03
  • Why down voting? Any suggestions to improve the question are welcome. – Xavi Valero Jun 21 '13 at 13:30
  • For convert CLLocationCoordinate2D to CGPoint see answer here - http://stackoverflow.com/a/37276779/2697425 – Savchenko Dmitry May 19 '16 at 19:32

1 Answers1

9
CGPoint myPoint = CGPointMake(coordinate.longitude, coordinate.latitude);

Note that the axes are swapped. But unless you give a coordinate system that you want the coordinate converted to, your question doesn't make sense.

nevan king
  • 112,709
  • 45
  • 203
  • 241
  • I need to convert the geographic coordinates to iPad's screen coordinate as in http://stackoverflow.com/questions/16124171/convert-decimal-latitude-longitude-coordinates-to-ipad-screen-coordinates. I am trying to draw line/path based on the converted coordinate values. – Xavi Valero Jun 21 '13 at 12:42
  • Find the bounding box of all the coordinates, then normalize for the screen bounds (something like subtract the minimum values of latitude and longitude from all, divide by max, multiply by screen size). – nevan king Jun 21 '13 at 13:32
  • 1
    So the above conversion wont suit my requirements. – Xavi Valero Jun 21 '13 at 14:09