Google 地图解码的 GMSPath 不正确 iOS

Google Maps decoded GMSPath incorrect iOS

因此,我在我的应用程序中使用了指示 API。但是,当我从响应中解码多段线时,它没有正确显示。这是我的代码:

    //Construct request URL
    NSString *urlString = [NSString stringWithFormat:
                           @"%@?origin=%f,%f&destination=%f,%f&sensor=true&key=%@",
                           @"https://maps.googleapis.com/maps/api/directions/json",
                           userMarker.position.latitude,
                           userMarker.position.longitude,
                           place.coordinate.latitude,
                           place.coordinate.longitude,
                           @"AIzaSyDrtHA-AMiVVylUPcp46_Vf1eZJJFBwRCY"];

    NSURL *directionsURL = [NSURL URLWithString:urlString];


    //Get directions in JSON format
    dispatch_async(dispatch_get_main_queue(), ^{
        NSData* data = [NSData dataWithContentsOfURL:directionsURL];

        NSError* error;

        if(data){
            NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

            //Parse JSON and plot route on map
            NSDictionary *routes = [json objectForKey:@"routes"][0];

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

            //Clear map from previous polylines
            [self.mapView clear];

            //Make polyline
            GMSPath *path = [GMSPath pathFromEncodedPath:overview_route];
            GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
            polyline.strokeWidth = 4;
            polyline.strokeColor = [UIColor darkGrayColor];
            polyline.map = self.mapView;
});

这是折线:

正如你所见,它没有正确地沿着道路行驶。但是,对我来说似乎没有足够的点来进行适当的弯曲。

编辑:这种情况只有 50% 的时间会发生,有时会正确显示,有时不会。

我做错了什么?

按此进行(使用 js API 而不是您正在使用的 json API):

Get a polyline from Google maps directions V3

看起来您应该在响应中使用 legs 每个步骤中的线条,而不是 overview_polyline 这可能只是粗略的近似线条。