我目前正在构建一个iOS应用程序,我希望实现一个功能,用户的位置显示在Google Map视图上,以及它们何时移动一个多段线节目是用户到目前为止所走过的路径。这显然需要实时发生。如何跟踪用户的位置并显示使用谷歌地图移动的路径ios SDK
到目前为止,我已经初始化了Google Maps视图,并且可以使用observeValueForKeyPath函数来显示用户的当前位置。随着用户移动,视图和位置标记更新。
我想要做到这一点的最佳方法是创建一个GMSMutablePath对象,每当地图摄像机更新到新位置时添加用户的当前位置,然后从该路径创建折线。我已经使用这个代码如下:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"myLocation"] && [object isKindOfClass:[GMSMapView class]])
{
[self.myMapView animateToCameraPosition:[GMSCameraPosition cameraWithLatitude:self.myMapView.myLocation.coordinate.latitude
longitude:self.myMapView.myLocation.coordinate.longitude
zoom:18]];
[trackedPath addCoordinate:CLLocationCoordinate2DMake(self.myMapView.myLocation.coordinate.latitude, self.myMapView.myLocation.coordinate.longitude)];
GMSPolyline *testPoly = [GMSPolyline polylineWithPath:trackedPath];
testPoly.strokeWidth = 8;
testPoly.strokeColor = [UIColor redColor];
testPoly.map = myMapView;
}
}
这不会产生任何地图折线在实践中因此任何帮助/建议将不胜感激!
代码中的点是什么? –
@sandeeptomar point是一个NSMutable Array。 – ChenSmile