2015-09-04 61 views
1

我正在编写一个Swift应用程序,我使用SDK Skobbler来操纵一个地图。 应用程序显示圈:UIBezierPath - 什么是单位半径

func displayCircle(x: Int, y: Int, radius: Int){...} //display circle in the map 

此外,我检查,如果用户在此领域中:

for area in self.areas { 

      var c = UIBezierPath() 

      let lat = area.getLatitude() 
      let long = area.getLongitude() 
      let radius = area.getRadius()/1000 
      let center = CGPoint(x: lat, y: long) 

      c.addArcWithCenter(center, radius: CGFloat(radius), startAngle: CGFloat(0), endAngle: CGFloat(360), clockwise: true) 
      if c.containsPoint(CGPoint(x: currentLocation.latitude, y: currentLocation.longitude)) { 
       //I AM IN THE AREA 
      }else { 
       //I AM NOT IN THE AREA 
      } 
      c.closePath() 
     } 

当我在圈子里,它的工作原理,但是,当我outsite的圈子里也适用...

我认为这个问题是关系到单位半径

  • skobbler - >单位米
  • UIBezierPath - 单位?

谢谢您的帮助

Ysee

回答

1

不回答你的问题,但你应该使用CoreLocation功能对于任务:

let current = CLLocation(latitude: currentLocation.latitude, longitude: currentLocation.longitude) 
    for area in self.areas { 
     let center = CLLocation(latitude: CLLocationDegrees(area.getLatitude()), longitude: CLLocationDegrees(area.getLongitude())) 
     if current.distanceFromLocation(center) <= CLLocationDistance(area.getRadius()) { 
      //I AM IN THE AREA 
     } 
     else { 
      //I AM NOT IN THE AREA 
     } 
    } 
+0

好吧,我会试试这个代码。谢谢 – Maybe1

1

iOS的单位是点。
在非视网膜设备中,1个点等于1个像素。 在视网膜设备(@ 2x)中,1点等于两个像素。 在@ 3x设备(Iphone 6 plus)中,1点等于三个像素。

关心角度。单位是弧度不是度数。 所以你需要将你的度数转换为弧度,你的角度应该是2 * M_PI,这对应于360度。你可以定义一个扩展来进行转换:

extension Int { 
     var degreesToRadians : CGFloat { 
      return CGFloat(self) * CGFloat(M_PI)/180.0 
     } 
    } 
    45.degreesToRadians // 0.785398163397448 
+0

谢谢你这个有用的信息! :) – Maybe1