- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在开发一个导航应用程序并跟踪用户在已绘制的 GMSPolyline 上的当前移动。当用户直行时效果很好。现在,假设 GMSPolyline 上有右转/左转或掉头,现在根据我的 GPS 位置,我在转弯前 20 米左右得到一个更新,在 30 米后得到另一个更新。
我的 GPS 无法收集恰好在转折点存在的点。在这种情况下,我的 GMSMarker 从 x 点跳到 y 点,如果我应用动画,它就会沿对角线移动,而不是沿着 GMSPolyline 弧线或曲线移动。请建议我如何从 GMSPolyline 收集那些缺失的点或为 GMS 标记显示一些动画,以便用户可以看到他实际上正在打开折线。
我附上一张示例图片。红线可以理解为 GMSPolylines,蓝点是我通过 CLLocation Manager 接收到的 GPS 坐标。
最佳答案
// While drawing polyline on GMSMapView
GMSPath *path = [GMSPath pathFromEncodedPath:strEncodedPolyline]; // Decoding encoded polyline string for converting to locations.
// Capture all path points in to a global array,So that we can track how user is travelling later.
arrLocationsOnPolyline = [NSMutableArray new]; // Make it fresh before filling
for (int counter = 0; counter < path.count; ++counter)
{
CLLocationCoordinate2D coordinate = [path coordinateAtIndex:counter];
CLLocation *locTemp = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
[arrLocationsOnPolyline addObject:locTemp];
}
// Here,After loop ending, we'll get all path points as locations in to arrLocationsOnPolyline
// Now in -locationManager:didUpdateLocations: delegate method,
// 1. Find the index of nearest path point to user's current location in arrLocationsOnPolyline,Lets call it as nFoundAtIndexTemp.
// FMI : loop through the arrLocationsOnPolyline and find the nearest point's index to user's current location,
// Hold a global nLastFoundAtIndex variable and make it's default value as -1(in -viewDidLoad or somewhere),
// 2. Check
if (nLastFoundAtIndex >= 0 && nFoundAtIndexTemp > (nLastFoundAtIndex + 10)) // (Means app didn't received location updates but user actually traveled through more than 10 points on poyline drawn)
{
// 3. Hurray,You got him,Now animate your blue current location marker from the location at last stored nearest path point index and current nearest path point index of arrLocationsOnPolyline
}
// 4. Update nLastFoundAtIndex with current state
nLastFoundAtIndex = nFoundAtIndexTemp;
// Code To Animate user location marker through the missed points
// Call this function with array of user missed points(Probably from -locationManager:didUpdateLocations:),Marker will be animated through the points.
#pragma mark - Animating through the missed coordinates
-(void)animateMarker:(GMSMarker *)markerUserLocation throughTheMissedLocations:(NSMutableArray <CLLocation *> *)arrMissedLocations
{
@try
{
CLLocation *locTemp = arrMissedLocations.firstObject;
if(locTemp)
{
[CATransaction begin];
NSTimeInterval nAnimationDuration = 0.1; // Update this value as per your needs.
[CATransaction setAnimationDuration:nAnimationDuration];
markerUserLocation.position = locTemp.coordinate;
if(arrMissedLocations.count >= 1)
{
@try
{
[CATransaction setCompletionBlock:^
{
@try
{
[arrMissedLocations removeObject:locTemp];
[self animateMarker:markerUserLocation throughTheMissedLocations:arrMissedLocations];
}
@catch (NSException *exception)
{
NSLog(@"exception at %s function %@",__PRETTY_FUNCTION__,exception.debugDescription);
}
}];
}
@catch (NSException *exception)
{
NSLog(@"exception at %s function %@",__PRETTY_FUNCTION__,exception.debugDescription);
}
}
[CATransaction commit];
}
}
@catch (NSException *exception)
{
NSLog(@"exception at %s function %@",__PRETTY_FUNCTION__,exception.debugDescription);
}
}
我们之前做过这个,但是不能贴代码,但是希望你能得到一个设计层面的想法。
希望对您有所帮助。
关于ios - GMSMarker 在 GMSPolyline 上的拐角处弹跳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41060922/
在允许用户在各种不同类型的 map 上显示复杂位置点列表(我们称之为轨迹)的 GPS 应用中,每个轨迹可以包含 2k 到 10k 个位置点。当轨迹在非 Google map 类型上呈现时,它们会被大量
我看到 GMSPolyline 协议(protocol)已经为其描边颜色定义了一个 color 属性,但是有没有办法对其多边形内部进行阴影处理(理想情况下具有透明度) ?我正在寻找相当于 MKPoly
将折线添加到 map 后,有时会出现连线现象。就像线条发生了变形和旋转一样。缩放 map 时,线条在晃动。 我录制了一段视频: https://drive.google.com/file/d/14mY
我已经在使用GMSGeometryContainsLocation的方法了为了确定坐标(来自点击用户)是否在 GMSPolygon 内,但我不能让它适用于 GMSPolyline。 -(void) d
我正在使用适用于 ios 的 google map sdk 来提供当前用户位置和结束位置之间的方向。到目前为止,我已经使用下面的代码在当前用户位置和结束位置之间绘制了一条 GMSPolyline,并且
,在我们的应用程序中,用户可以在 map 上创建 GMS- 要素。然后这些功能是可编辑的,编辑过程从点击开始。在某些情况下,如果应用于折线的样式是 1 点或 2 点线,则用户很难点击它们。我对此进行了
你好,在我当前的项目中我有: class SecondController: UIViewController, CLLocationManagerDelegate { var allPoly : [
我需要在某些情况下将 GMSPolyline 从一个位置移动到另一个位置。这是场景: 用户打开 GMSMapView 并创建 GMSPolyline 要素。 然后用户改变 map 位置 用户点击一个按
我正在使用 GoogleMap-IOS-1.8.1 SDK 来显示 map 。我必须在 map 上绘制一条 GMSPolyline。在特定事件之后,我必须删除除标记之外的所有 GMSPolyline
我正在开发一个应用,它使用 NextBus API 和 Google map 显示公交路线。但是,我遇到了 CPU 使用问题,我认为这是由 map 上的 GMSPolylines 数量引起的。路线由一
我正在开发一个导航应用程序并跟踪用户在已绘制的 GMSPolyline 上的当前移动。当用户直行时效果很好。现在,假设 GMSPolyline 上有右转/左转或掉头,现在根据我的 GPS 位置,我在转
我正在使用谷歌地图 iOS sdk。我使用以下代码在我的谷歌地图上添加了折线。但现在我想在这一行的末尾添加箭头。如何解决这个问题? GMSMutablePath *path = [GMSMutable
我使用的是谷歌地图 SDK,我必须在用户移动时绘制多段线,目前它只为标记设置动画,在图钉移动到特定位置之前绘制路径。我必须同时绘制路径和移动图钉。 查看此视频:https://www.dropbox.
我正在努力检测在我的 Google map 上绘制的 GMSPolyline 上的点击,它适用于 GMSpolygones,但同样的方法似乎不适用于折线。我目前适用于多边形的方法是: if (GMSG
我在互联网上找不到任何 Google Maps SDK 最佳实践,所以我在这里问。我正在开发一个包含大量 GMSMarkers (200+) 和 GMSPolylines (9000+) 的应用程序。
我对谷歌地图还很陌生,这个问题已经困扰我好几天了。 我基本上有一组坐标点,我将其转换为 GMSPath 对象。然后使用此路径对象在我的 GMSMapView 上绘制和呈现 GMSPolyline。这绝
我正在使用谷歌距离 API ["https://maps.googleapis.com/maps/api/directions/json?origin= "+start.latitude + ","+
我在 iOS 7.1 中使用 google map sdk 如何为 GMSPolyline 设置颜色,默认为黑色。我尝试使用 setStrokeColor 和 setSpans: setStrokeC
根据入门指南添加了所有内容。加载 map ,我可以毫无问题地将 GMSMarker 添加到 map 中。我有一个绘制多边形的方法,但应用程序每次都会崩溃。 方法: -(void)drawPolygon
我是一名优秀的程序员,十分优秀!