Roger Gardner
Roger Gardner

Reputation: 13

MKMapPoint to CGPoint

I have successfully drawn an MKPolygon over a local mapView in Swift2.0 in an iPhone app. I imported CLLocationCordinate2D's and the result is perfect.

However my real aim is draw this overlay in a UIView as the graphic will be part of a data analysis app (where users can create a chart as a png and use in PowerPoint etc). I was thinking of a UIBezierPath.

I have tried the mapView.convert methods to take my CLLocationCordinate2D's to another view and the points are very very close together. ultimate aim

If my mapView is 645w x 399h I would expect the black dots to be in the range of (approx) (34, 93), (59, 160), (108, 165), (112, 193), (131,202) etc (computed from the top left corner).

Nothing works on a locally scaled map and I am stuck for ideas. Really grateful for advice.

Upvotes: 0

Views: 705

Answers (1)

Apurv
Apurv

Reputation: 17186

Each time when you pan or zoom the map, the associated CGPoint get change. So while you translate your co-ordinates to CGPoint, make sure you have adjusted your map and then only you translate map points to CGPoint.

Create a UIView of same size as MKMapView. Add MKMapView to UIView. This will make sure to have same CGPoint with reference to your parent view.

Below line will then help you to translate your map co-ordinate to CGPoint.

[self.mapView convertCoordinate:your_map_coordinate toPointToView:self.view]

Upvotes: 1

Related Questions