我发现这个Objective-C tip on Stackoverflow.但我遇到的问题是它从mapVIEw转换0,0(纬度/经度为-180,-180.Aka,南极).
所以代替:
topleft = mapVIEw.convertPoint(CGPointMake(0,0),toCoordinateFromVIEw: self.mapVIEw)
我想我可以做到:
topleft = vIEw.convertPoint(CGPointMake(0,toCoordinateFromVIEw: self.mapVIEw)
但我得到错误:
Cannot invoke ‘convertPoint’ with an argument List of type ‘(CGPoint,
toCoordinateFromVIEw: MKMapVIEw!)’
我花了一天时间试图解决这个问题,但无济于事,我来找你寻求指导.任何帮助将非常感激.
这是完整的功能:
func findCornerLocations(){ var topleft = CLLocationCoordinate2D() let mapVIEw = MKMapVIEw() topleft = vIEw.convertPoint(CGPointMake(0,toCoordinateFromVIEw: self.mapVIEw) print(topleft.latitude,topleft.longitude)}解决方法 你非常,非常接近!
let topleft = map.convertPoint(CGPointMake(0,toCoordinateFromVIEw: self.vIEw)let bottomleft = map.convertPoint(CGPointMake(0,self.vIEw.frame.size.height),toCoordinateFromVIEw: self.vIEw)
实施时,它看起来像这样:
let map = MKMapVIEw() map.frame = CGRectMake(100,100,100) let coord = CLLocationCoordinate2DMake(37,-122) let span = MKCoordinateSpanMake(1,1) map.region = MKCoordinateRegionMake(coord,span) self.vIEw.addSubvIEw(map) let topleft = map.convertPoint(CGPointMake(0,toCoordinateFromVIEw: self.vIEw) let bottomleft = map.convertPoint(CGPointMake(0,toCoordinateFromVIEw: self.vIEw) print("top left = \(topleft)") print("bottom left = \(bottomleft)")总结
以上是内存溢出为你收集整理的ios – 将视点转换为MKMapView坐标全部内容,希望文章能够帮你解决ios – 将视点转换为MKMapView坐标所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)