如何在谷歌地图目标上旋转自定义标记图像c [英] How to rotate custom marker image on google map objective c
问题描述
NSArray
中,我尝试显示那些 Lat& 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 = @标题;
marker.snippet = @Sub title;
marker.map = self.gMapView;
}
但是我正在寻找 UIDesign&功能如下:
Can任何一个帮助我怎么能显示用户当前位置&驱动程序的注释列表
(如何在Google地图上旋转自定义标记图像)
在方向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(度数:双精度) - >双{
返程度*(M_PI / 180)
}
func ToBearing(弧度:双精度) - > Double {
return(ToDegrees(弧度)+ 360)%360
}
func ToDegrees(弧度:双倍) - >双{
返回弧度* 180 / M_PI
}
并为制造商设置轮转
maker.rotation = DegreeBearing(self.fromPoint,B:self.toPoint)
下面更新了ObjC代码
- (double)DegreeBearing:(CLLocation *)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))];
$ b - (double)ToRad :(双)度{
返回度*(M_PI / 180);
$ b - (double)ToBearing:(double)radians {
double degree = [self ToDegrees:radians];
回报度+ 360%360;
}
- (double)ToDegrees:(double)radians {
返回弧度* 180 / M_PI;
}
Currently i am working an app like Uber iOS application. I Already integrated Google Maps SDK and I showed custom image for User current location also. Currently I am getting some Driver's Current location details(Ex: 100 Driver's) from server. I saved in one NSArray
and I tried to display those Lat & Long on GoogleMaps by using following code:
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;
}
But I am looking UIDesign & Functionality like this:
Can Any one help me out how can I show User Current location & Driver's list of Annotations
(How to rotate custom marker image on google map)
In directions API (apple or google map) have a list points. So , to calculate the angle between two points, you can:
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
}
and set rotation for maker
maker.rotation = DegreeBearing(self.fromPoint, B: self.toPoint)
Updated ObjC Code below
-(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;
}
这篇关于如何在谷歌地图目标上旋转自定义标记图像c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!