小编lai*_*bug的帖子

C - 在跟踪索引的同时对float数组进行排序

我有一个包含3个浮点值的数组:

float norms[3];

norms[0] = 0.4;
norms[1] = 3.2;
norms[2] = 1.7;
Run Code Online (Sandbox Code Playgroud)

我想按降序对此数组进行排序,同时跟踪数组中值的原始索引.

换句话说,给定norms[] = {0.4, 3.2, 1.7}具有相应索引的数组{0, 1, 2},我基本上想要获得一个对应的数组,该数组ints反映了按降序排序的float值的原始位置norms[].在这种情况下,它会{1, 2, 0}.

实现这一目标的最佳/最干净的方法是什么?

c arrays sorting

10
推荐指数
1
解决办法
3868
查看次数

如何使用Google Maps ios SDK跟踪用户的位置并显示行进路径

我目前正在构建一个ios应用程序,我希望实现一个功能,其中用户的位置显示在Google Map视图上,当他们移动折线显示时,用户到目前为止已经行进的路径.这显然需要实时发生.

到目前为止,我已经初始化了Google地图视图,并可以使用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;
    }
}
Run Code Online (Sandbox Code Playgroud)

这在实践中不会在地图上产生任何折线,所以任何帮助/建议将非常感谢!

google-maps polyline ios google-maps-sdk-ios

5
推荐指数
1
解决办法
7169
查看次数

标签 统计

arrays ×1

c ×1

google-maps ×1

google-maps-sdk-ios ×1

ios ×1

polyline ×1

sorting ×1