Google Map SDK:在Google地图中绘制正确的折线,作为设备在后台移动 [英] Google Map SDK: Draw correct polyline in google map as Device Moves in Background

查看:451
本文介绍了Google Map SDK:在Google地图中绘制正确的折线,作为设备在后台移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于iOS的Google Map SDK。我在驾驶模式下绘制折线。

I am using Google Map SDK for iOS. I am drawing polylines in Driving mode.

但是当我停下来然后缩放谷歌地图时,我的当前位置光标会自动移动并重绘之字形折线,因为之前所有绘制的折线重叠,折线完全改变。当我进入背景和驾驶时会发生事情。

But when i stop,and Zoom google map then, my Current position cursor automatically moves and redraw zigzag polylines, due to that all previous polylines drawn get overlapped and polylines get completely changed.Same things happens when i go in background and drive.

我能知道它为什么会发生吗?如何在同一路径中同时在驾驶和步行模式下绘制平滑折线。

Could i know why is it happening? And How can I draw smooth polylines in driving and walking mode same time in same path.

我的代码 -

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
 pointString=[NSString     stringWithFormat:@"%f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude];
CLLocationDistance kilometers = [newLocation distanceFromLocation:oldLocation] / 1000;
NSLog(@"Distance Travelled in Kilometer :%f",kilometers);

[self.points addObject:pointString];
GMSMutablePath *path = [GMSMutablePath path];
for (int i=0; i<self.points.count; i++)
{
    NSArray *latlongArray = [[self.points   objectAtIndex:i]componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];

    [path addLatitude:[[latlongArray objectAtIndex:0] doubleValue] longitude:[[latlongArray objectAtIndex:1] doubleValue]];
}

if (self.points.count>2)
{
    GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
    polyline.strokeColor = [UIColor blueColor];
    polyline.strokeWidth = 5.f;
    polyline.map = mapView_;
    self.mapContainerView = mapView_;
}
}

如果,我保持相同的位置,那么Googme地图光标位置自动移动并绘制这样的折线。

If , I remain in Same position, then Googme map Cursor position automaticalaly moves and draw polylines like this.

推荐答案

添加 NSLocationAlwaysUsageDescription UIBackgroundModes - >location到Info.plist

add a NSLocationAlwaysUsageDescription and a UIBackgroundModes -> "location" to Info.plist

AND

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
    manager.allowsBackgroundLocationUpdates = YES;
}

在允许后台位置更新之前:
在此处输入图像说明

Before allowing background location updtaes: enter image description here

允许后台位置更新后:
在此输入图片说明

After Allowing background location updtaes: enter image description here

这个行程的大部分都是在后台绘制的。

Most of this itinerary has been drawn in the background.

这篇关于Google Map SDK:在Google地图中绘制正确的折线,作为设备在后台移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆