Ios 自定义地理位置的简单指南针方向
指向自定义地理位置方向的简单指南针,您可以通过提供该位置的纬度和经度来指定该位置。 我试过了,但也有错误 我不知道这个错误在哪里 类ViewController:UIViewController、CLLocationManagerDelegate{ var locationmanager:CLLocationManagerIos 自定义地理位置的简单指南针方向,ios,iphone,swift,geolocation,compass-geolocation,Ios,Iphone,Swift,Geolocation,Compass Geolocation,指向自定义地理位置方向的简单指南针,您可以通过提供该位置的纬度和经度来指定该位置。 我试过了,但也有错误 我不知道这个错误在哪里 类ViewController:UIViewController、CLLocationManagerDelegate{ var locationmanager:CLLocationManager @IBOutlet var arrowImageView: UIImageView! var currentHeading = CLHeading() var userL
@IBOutlet var arrowImageView: UIImageView!
var currentHeading = CLHeading()
var userLocation: CLLocationCoordinate2D!
var destLocation: CLLocationCoordinate2D!
var latitudeOfTargetedPoint = 48.858093
var longitudeOfTargetedPoint = 2.294694
var angle:Float!
override func viewDidLoad() {
super.viewDidLoad()
locationmanager = CLLocationManager()
locationmanager.delegate = self
locationmanager.desiredAccuracy = kCLLocationAccuracyBest
locationmanager.requestWhenInUseAuthorization()
locationmanager.startUpdatingLocation()
locationmanager.distanceFilter = 100.0
locationmanager.startUpdatingHeading()
}
func showUserAndDestinationOnMap()
{
// Calculate the rectangle that contains the current position and the destination
var maxLat:Double = fmax(userLocation.latitude, latitudeOfTargetedPoint)
var maxLon:Double = fmax(userLocation.longitude, longitudeOfTargetedPoint)
var minLat:Double = fmin(userLocation.latitude, latitudeOfTargetedPoint)
var minLon:Double = fmin(userLocation.longitude, longitudeOfTargetedPoint)
// Calculate the latitude, longitude width when displaying map
var mapMargin:Double = 1.5; // Width route enters (1.0) + margin (0.5)
var leastCoordSpan:Double = 0.005; // Enlarge maximum value when the display
var span_x:Double = fmax(leastCoordSpan, fabs(maxLat - minLat) * mapMargin);
var span_y:Double = fmax(leastCoordSpan, fabs(maxLon - minLon) * mapMargin);
var span:MKCoordinateSpan = MKCoordinateSpanMake(span_x, span_y);
// Calculate the center of the destination your location
var center:CLLocationCoordinate2D = CLLocationCoordinate2DMake((maxLat + minLat) / 2, (maxLon + minLon) / 2);
var region:MKCoordinateRegion = MKCoordinateRegionMake(center, span);
}
func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
self.showUserAndDestinationOnMap()
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println(error)
}
func locationManager(manager: CLLocationManager!, didUpdateHeading newHeading: CLHeading!) {
var degrees = newHeading.magneticHeading
if (degrees > 180)
{
degrees = 360 - degrees;
}
else
{
degrees = 0 - degrees;
}
// Rotate the arrow image
if self.arrowImageView != nil {
UIView.animateWithDuration(3.0, animations: { self.arrowImageView.transform = CGAffineTransformRotate(self.arrowImageView.transform,self.DegreesToRadians(degrees) ) })
}
}
func degreestoradis(值:Double)->CGFloat{
返回CGFloat(值*M_PI/180.0)
}
func RadiansToDegrees(值:Double)->CGFloat{
返回CGFloat(值*180.0/M_PI)}
如果有人能做到这一点
对不起,我的英文是:p~有什么错误/消息?哪些行?没有错误项目正在工作,但问题在于箭头如果我运行应用程序箭头图像旋转很快,我希望箭头指南针指向方向,如果你不明白,请在此处下载项目@Paulw11检查链接