我正在尝试为应用程序开发一个指南针,它在地图上有一组注释.我希望能够选择一个注释,然后让指南针将用户指向所选位置.
我已经计算了从用户位置到注释位置的degress,我有磁性标题和iPhone的真实标题.我也知道如何旋转图像.但我无法弄清楚下一步是什么.
用户位置和注释位置之间的度数计算如下:
// get user location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
float x1 = coordinate.latitude;
float y1 = coordinate.longitude;
float x2 = [annLatitude floatValue];
float y2 = [annLongitude floatValue];
float dx = (x2 - x1);
float dy = (y2 - y1);
if (dx == 0) {
if (dy > 0) {
result = 90;
}
else …
Run Code Online (Sandbox Code Playgroud) 我需要创建一个iPhone简单视图,根据用户在世界中的位置,将该人指向永不改变的长/拉位置.
是否可以通过iPhone API了解这一点?
任何例子?
注意:-(集成AppleMap
,不兼容GoogleMap
)
我已经完成以下工作:
我的要求:
当用户朝不同方向停留在同一位置(或不同位置)时,引脚(在当前位置)应自动指向用户指向的方向。
例如:如果划船显示在用户位置位置,并且指向北,但是如果用户向西移动,则划船(用户位置图钉)也应指向该方向。
尝试使用以下代码:
//MARK:Change Direction Methods
func angle(fromCoordinate first: CLLocationCoordinate2D, toCoordinate second: CLLocationCoordinate2D) -> Float {
let deltaLongitude = second.longitude - first.longitude
let deltaLatitude = second.latitude - first.latitude
let angle = (.pi * 0.5) - atan(deltaLatitude / deltaLongitude)
if deltaLongitude > 0 {
return Float(angle)
}
else if deltaLongitude < 0 {
return Float(angle) + .pi
}
else if deltaLatitude < 0 {
return .pi
} …
Run Code Online (Sandbox Code Playgroud)