【问题标题】:Google Map draw Polyline following device direction in iOS谷歌地图在iOS中按照设备方向绘制折线
【发布时间】:2015-03-17 08:29:44
【问题描述】:

我正在做一个导航应用程序,它使用 Google 地图方向 API,我要求 Google Api 使用“驾驶模式”在两个坐标之间绘制路径,然后在地图上绘制它。我在开车时遇到问题,我重新计算了从当前位置到某个目的地位置的路径,但是我得到的路径没有跟随我的设备方向,当我在双向行驶时它以相反的方向运行路。

我没有找到任何解决方案。 (你可以在这个链接看到我用我的 iphone 做的屏幕截图:https://imageshack.com/my/images

感谢您的帮助。

【问题讨论】:

  • 用户使用 CLLocationDirection 来纠正这个问题
  • 感谢您的回复,如果您要查看,我发布了我的代码,这样折线路径将遵循我的位置方向吗?

标签: ios iphone google-maps cllocationmanager google-polyline


【解决方案1】:
Thanks for your reply, i did this: 
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{

    if (newHeading.headingAccuracy < 0)
        return;

    // Use the true heading if it is valid.
    CLLocationDirection  theHeading = ((newHeading.trueHeading > 0) ?
                                       newHeading.trueHeading : newHeading.magneticHeading);

    [map.mapView animateToBearing:currenHeading];
    userLocation = manager.location;
    markerUserLocation.position = CLLocationCoordinate2DMake(userLocation.coordinate.latitude,userLocation.coordinate.longitude);
    markerUserLocation.map=map.mapView;
    [map.mapView animateToViewingAngle:50];
    [map.mapView animateToZoom:19];

    currenHeading = theHeading;
    if(etapes.count > 0)
    {
    //Here i start navigation        
     [self NavigateToLeg:etapes];

    }

}

and the function NavigatToLeg: 

 -(void)NavigateToLeg:(NSMutableArray *)Steps {
polyline.map = nil;
        polyline = nil;

        NSDictionary *routes = [json objectForKey:@"routes"][0];
        NSDictionary *route = [routes objectForKey:@"overview_polyline"];
        NSString *overview_route = [route objectForKey:@"points"];

        /******************************** ON TRACE LE CHEMIN ************************************/
        GMSPath *path = [GMSPath pathFromEncodedPath:overview_route];
        polyline = [GMSPolyline polylineWithPath:path];
        polyline.strokeWidth = 10.f;
        polyline.strokeColor = [UIColor orangeColor];
        polyline.map = map.mapView;
        /******************************** FIN ************************************/

        /******************************** ON RECUPERE LES ETAPES ET ON LANCE LA NAVIGATION ************************************/

        // on récupère les indications avec leurs coordonnées :
        NSArray * legs = [routes objectForKey:@"legs"];
        etapes = [[legs objectAtIndex:0] objectForKey:@"steps"];
 NSLog(@"ETAPES COUNT = %d",etapes.count);
    NSLog(@"ETAPES NUMERO = %d",etapeCount);


    if(etapeCount < etapes.count){
    leg = [self getLegFromSteps:Steps forIndex:etapeCount];
    distanceLabel.text = [NSString stringWithFormat:@"%d m",[self roundUpDistance:(int)[userLocation distanceFromLocation:leg.endLoc]]];
    //[NSString stringWithFormat:@"%d m",[self roundUpDistance:leg.distance]];


    NSLog(@"Polyline Points: %@",leg.polyline.path);

    leg.polyline.strokeWidth = 10.f;
    leg.polyline.strokeColor = [UIColor blueColor];
    leg.polyline.map = map.mapView;
    //[map.mapView animateToLocation:userLocation.coordinate];
    [map.mapView animateToViewingAngle:50];
    [map.mapView animateToZoom:19];

}

这样做,路径会跟随我的方向吗?

谢谢。

【讨论】:

  • 为什么要使用google api来绘制路线?您还可以使用在位置管理器中获得的 GPS 点绘制路线。
  • 问题是您的移动 GPS 点与 Google API 响应不完全相同。因此,最好使用您从位置管理器更新中收到的设备 GPS 点来渲染路径。
  • 在没有 Google Api 的情况下我将如何渲染路径以及如何获得道路?
  • 但是 Google Map 与 Google Api 配合使用,它从不显示我道路的相反方向。
猜你喜欢
  • 1970-01-01
  • 2018-03-06
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 2013-07-02
  • 2023-04-06
相关资源
最近更新 更多