目前我正在使用像Uber iOS应用程序这样的应用程序。我已经集成了Google Maps SDK,我也为用户当前位置显示了自定义图像。目前我从服务器获得了一些Driver的当前位置详细信息(例如:100个驱动程序)。我保存了一个NSArray
,我试图显示那些 Lat&amp;使用以下代码在GoogleMaps上<长> :
for(int i=0;i<[latLongArr count];i++)
{
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake([[(NSDictionary *)[latLongArr objectAtIndex:i] valueForKey:@"Latitude"] doubleValue], [[(NSDictionary *)[latLongArr objectAtIndex:i] valueForKey:@"Longitude"] doubleValue]);
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.title = @"Title";
marker.snippet = @"Sub title";
marker.map = self.gMapView;
}
但我正在寻找 UIDesign&amp;功能性是这样的:
可以任何人帮助我如何显示用户当前位置&amp;司机的注释清单
(如何在Google地图上旋转自定义标记图像)
答案 0 :(得分:6)
在方向API(苹果或谷歌地图)上有一个列表点。因此,要计算两点之间的角度,您可以:
func DegreeBearing(A:CLLocation,B:CLLocation)-> Double{
var dlon = self.ToRad(B.coordinate.longitude - A.coordinate.longitude)
let dPhi = log(tan(self.ToRad(B.coordinate.latitude) / 2 + M_PI / 4) / tan(self.ToRad(A.coordinate.latitude) / 2 + M_PI / 4))
if abs(dlon) > M_PI{
dlon = (dlon > 0) ? (dlon - 2*M_PI) : (2*M_PI + dlon)
}
return self.ToBearing(atan2(dlon, dPhi))
}
func ToRad(degrees:Double) -> Double{
return degrees*(M_PI/180)
}
func ToBearing(radians:Double)-> Double{
return (ToDegrees(radians) + 360) % 360
}
func ToDegrees(radians:Double)->Double{
return radians * 180 / M_PI
}
并设置制造商的轮值
maker.rotation = DegreeBearing(self.fromPoint, B: self.toPoint)
更新了以下的ObjC代码
-(double) DegreeBearing:(CLLocation*) A locationB: (CLLocation*)B{
double dlon = [self ToRad:(B.coordinate.longitude - A.coordinate.longitude)];
double dPhi = log(tan([self ToRad:(B.coordinate.latitude)] / 2 + M_PI / 4) / tan([self ToRad:(A.coordinate.latitude)] / 2 + M_PI / 4));
if (fabs(dlon) > M_PI){
dlon = (dlon > 0) ? (dlon - 2*M_PI) : (2*M_PI + dlon);
}
return [self ToBearing:(atan2(dlon, dPhi))];
}
-(double) ToRad: (double)degrees{
return degrees*(M_PI/180);
}
-(double) ToBearing:(double)radians{
double degree = [self ToDegrees:radians];
return degree+360% 360;
}
-(double) ToDegrees:(double)radians{
return radians * 180 / M_PI;
}