Convert span value into meters on a mapview

前端 未结 6 828
小鲜肉
小鲜肉 2020-12-13 06:56

Whenever the user zoom in or out the map i need to know how many meters are currently represented on the map (width or height).

What i need is the inverse function o

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 07:47

    Thanks for the post all. I have an app that required a mile radius to figure out how many location records to fetch so this came in handy. Here is the swift equivalent for anyone who might come across this in the future.

    let mRect: MKMapRect = self.mapView.visibleMapRect
            let eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect))
            let westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect))
            let currentDistWideInMeters = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint)
            let milesWide = currentDistWideInMeters / 1609.34  // number of meters in a mile
            println(milesWide)
    

提交回复
热议问题