I have an image over a map and I want to give it some linear and rotational motion over the google maps.
How can I do it in GMS? Please help me.
I have an image over a map and I want to give it some linear and rotational motion over the google maps.
How can I do it in GMS? Please help me.
You could add the image as a marker and then use the layer property of that marker to add some animations using CoreAnimation
See the docs: developers.google.com/maps/documentation/ios/reference/
Actually I solved the problem by using following code and GMSMarker method setPosition: . The following code provides rotation to the images and using setPosition: we can place the marker/image anywhere. The combination of both gives required linear and rotational motion.
- (UIImage *)imageRotatedByDegrees:(CGFloat)degrees image: (UIImage*) image
{
CGSize size = image.size;;
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM( context, 0.5f * size.width, 0.5f * size.height ) ;
CGContextRotateCTM (context, DegreesToRadians(degrees));
[ image drawInRect:(CGRect){ { -size.width * 0.5f, -size.height * 0.5f }, size } ] ;
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
It's an easy process. First rotate the marker to get the right heading using this function:
+(float)getBearing:(CLLocationCoordinate2D)locations1 andSecond:(CLLocationCoordinate2D)locattion2{
float fLat = degreesToRadians(locations1.latitude);
float fLng = degreesToRadians(locations1.longitude);
float tLat = degreesToRadians(locattion2.latitude);
float tLng = degreesToRadians(locattion2.longitude);
float degree = radiansToDegrees(atan2(sin(tLng-fLng)*cos(tLat), cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(tLng-fLng)));
if (degree >= 0) {
return degree;
} else {
return 360+degree;
}
}
Then rotate your marker to the new heading:
YOUR_MARKER.rotation = CALCULATED_HEADING - 180;
Now, the final step is to animate your driver smoothly
[CATransaction begin];
[CATransaction setAnimationDuration:3.1];
[YOUR_MARKER setPosition:NEW_LOCATION_COORDINATES];
[CATransaction commit];