如何沿着Objective c中的坐标平滑移动GMSMarker [英] How to smoothly move GMSMarker along coordinates in Objective c
问题描述
我正在使用谷歌地图 sdk.我想每 5 秒更新一次 pin 的 GPS 坐标.目前我只是在更新 GMSMarker 的位置属性.但它提供了跳跃效果.我想在地图上平滑移动标记.
这是我更新标记位置的代码
I'm using google map sdk. I want to update gps coordinates of pin after each 5 seconds. Currently I'm just updating position attribute of GMSMarker. But it gives jump effect. I want to move marker smoothly on map.
Here is my code to update position of marker
-(void)updateLocationoordinates(CLLocationCoordinate2D) coordinates
{
if (marker == nil) {
marker = [GMSMarker markerWithPosition:coordinates];
marker.icon = [UIImage imageNamed:CAR_FOUND_IMAGE];
marker.map = mapView_;
} else
marker.position = coordinates;
}
推荐答案
将 else 块更改为更像这样的内容:
Change your else block to be something more like this:
[CATransaction begin];
[CATransaction setAnimationDuration:2.0];
marker.position = coordindates;
[CATransaction commit];
我们允许您使用核心动画进行动画制作谷歌地图.
We enable you to use Core Animation for animating Google Maps.
有关工作示例,请参阅 SDK 示例应用程序中的 AnimatedCurrentLocationViewController.{c,m}
.
For a worked sample, please see AnimatedCurrentLocationViewController.{c,m}
in the SDK sample application.
这篇关于如何沿着Objective c中的坐标平滑移动GMSMarker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!