无法使用iOS在google地图中绘制完整的多段线

无法使用iOS在google地图中绘制完整的多段线,ios,google-maps,path,google-maps-sdk-ios,polyline,Ios,Google Maps,Path,Google Maps Sdk Ios,Polyline,我试图在iOS上的谷歌地图中创建两个地方之间的路径。我可以使用下面的代码在两个地方之间绘制路径。在这段代码中,我使用的是google地图键和place键。当我给点靠近的时候,它就来了,但当我给v点远的时候,画一条路径,它并没有根据谷歌地图完美地转向 #导入“MPOWGetDirections.h” @实施指南 -(void)setSearchModeOption:(MPGetDirectionOption)选项 { searchModeOption=选项; NSLog(@“选项设置:%i”,选项

我试图在iOS上的谷歌地图中创建两个地方之间的路径。我可以使用下面的代码在两个地方之间绘制路径。在这段代码中,我使用的是google地图键和place键。当我给点靠近的时候,它就来了,但当我给v点远的时候,画一条路径,它并没有根据谷歌地图完美地转向

#导入“MPOWGetDirections.h”
@实施指南
-(void)setSearchModeOption:(MPGetDirectionOption)选项
{
searchModeOption=选项;
NSLog(@“选项设置:%i”,选项);
}
-(int)RequestDirectionsandShowOnMap:(GMSMapView*)aMapView
{
NSArray*模式=[[NSArray alloc]initWithObjects:@“运输”,“骑自行车”,“步行”,“驾驶”,无];
NSString*DEVITE=[[NSString alloc]initWithFormat:@'';
NSString*origin=[[NSString alloc]initWithFormat:@'';
NSString*destination=[[NSString alloc]initWithFormat:@'';
//===============================设置语言==========================
if(self.setLanguage)
self.setLanguage=[NSString stringWithFormat:@“language=%@”,self.setLanguage];
其他的
self.setLanguage=@“language=en”;
//=========================设置搜索模式==========================
if(searchModeOption==0)
{
if(自我离职日期==nil)
{
self.departDate=[NSDate-date];
}
出发=[NSString stringWithFormat:@“&出发时间=%i”(int)[self.departDate timeIntervalSince1970];
}
//=======================================集原生态==========================
if(自我起源)
{
origin=[nsstringwithformat:@“origin=%@”,self.origin];
}
else if(self.originCoordinate.latitude&&self.originCoordinate.longitude)
{
原点=[NSString stringWithFormat:@“原点=%f,%f”,self.originCoordinate.latitude,self.originCoordinate.longitude];
}
其他的
{
NSLog(@“未设置原点”);
返回-1;
}
//=========================设置目的地==========================
if(自我目的地)
{
destination=[NSString stringWithFormat:@“destination=%@”,self.destination];
}
else if(self.destinationCoordinate.latitude&&self.destinationCoordinate.longitude)
{
destination=[NSString stringWithFormat:@“destination=%f,%f”,self.destinationCoordinate.latitude,self.destinationCoordinate.longitude];
}
其他的
{
NSLog(@“未设置目的地”);
返回-1;
}
//======================设置完整Url和请求==========================
NSString*URLforRequest=[[NSString stringWithFormat:@]http://maps.googleapis.com/maps/api/directions/json?%@&%@&sensor=false&%@&alternative=true&mode=%@',来源、目的地、self.setLanguage[mode objectAtIndex:searchModeOption],deep]stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(@“%@”,URLforRequest);
NSURLRequest*requests=[NSURLRequest requestWithURL:[NSURL URLWithString:URLforRequest]];
[NSURLConnection sendAsynchronousRequest:请求队列:[NSOperationQueue mainQueue]完成处理程序:^(NSURLResponse*响应,NSData*数据,NSError*错误)
{
如果(错误==nil&&data)
{
//NSLog(@“%@,[[NSString alloc]initWithData:数据编码:NSUTF8StringEncoding]);
方向=[NSJSONSerialization JSONObjectWithData:数据选项:NSJSONReadingMutableLeaves错误:&错误];
如果(错误)
{
NSLog(@“%@”,错误);
}
NSString*状态=[directions objectForKey:@“状态”];
NSLog(@“状态:%@”,状态);
如果([状态为IsequalString:@“OK”])
{
[自我解码结果];
如果(aMapView)
[自我展示地图:aMapView];
}
}
其他的
NSLog(@“%@”,错误);
[[NSNotificationCenter defaultCenter]postNotificationName:@“请求完成”对象:nil];
}];
返回0;
}
-(无效)结果
{
self.destination=[[directions objectForKey:@“routes”]objectAtIndex:0]objectForKey:@“legs”]objectAtIndex:0]objectForKey:@“end_address”];
self.distance=[[[directions objectForKey:@“routes”]objectAtIndex:0]objectForKey:@“legs”]objectAtIndex:0]objectForKey:@“distance”]objectForKey:@“text”]doubleValue];
self.duration=[[[directions objectForKey:@“routes”]objectAtIndex:0]objectForKey:@“legs”]objectAtIndex:0]objectForKey:@“duration”]objectForKey:@“text”];
//获取指令数组
self.instrunctions=[[NSMutableArray alloc]init];
对于(int n=0;n>1):(结果>>1);
lat+=dlat;
移位=0;
结果=0;
做{
b=[编码字符索引:索引++]-63;
结果|=(b&0x1f)=0x20);
NSInteger dlng=((结果&1)~(结果>>1):(结果>>1));
液化天然气+=液化天然气;
NSNumber*纬度=[[NSNumber alloc]initWithFloat:lat*1e-5];
NSNumber*经度=[[NSNumber alloc]initWithFloat:lng*1e-5];
CLLocation*location=[[CLLocation alloc]initWithLatitude:[纬度浮点值]经度:[经度浮点值]];
[数组addObject:位置];
}
返回数组;
}
-(无效)showOnMap:(GMSMapView*)aMapView{
GMSPolyline*多段线=self.overviewPolyline;
polyline.strokeColor=[UIColor blueColor];
折线.strokeWidth=2.f;
polyline.geodesic=是;
polyline.map=aMapView;
}
@结束
`
有人知道我在做什么吗
GMSPolyline *polyPath = [GMSPolyline polylineWithPath:[GMSPath pathFromEncodedPath:encodedPath]];
-(void)drawPathFrom:(CLLocation*)source toDestination:(CLLocation*)destination{

    NSString *baseUrl = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=true", source.coordinate.latitude,  source.coordinate.longitude, destination.coordinate.latitude,  destination.coordinate.longitude];

    NSURL *url = [NSURL URLWithString:[baseUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSLog(@"Url: %@", url);
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if(!connectionError){
            NSDictionary *result        = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            NSArray *routes             = [result objectForKey:@"routes"];
            NSDictionary *firstRoute    = [routes objectAtIndex:0];
            NSString *encodedPath       = [firstRoute[@"overview_polyline"] objectForKey:@"points"];

            GMSPolyline *polyPath       = [GMSPolyline polylineWithPath:[GMSPath pathFromEncodedPath:encodedPath]];
            polyPath.strokeColor        = [UIColor redColor];
            polyPath.strokeWidth        = 3.5f;
            polyPath.map                = _mapView;
        }
    }];

}
//MARK: API CALL
func GetRoughtofTwoLocation(){
    let originString: String = "\(23.5800),\(72.5853)"
    let destinationString: String = "\(24.5836),\(72.5853)"
    let directionsAPI: String = "https://maps.googleapis.com/maps/api/directions/json?"
    let directionsUrlString: String = "\(directionsAPI)&origin=\(originString)&destination=\(destinationString)&mode=driving"

    APICall().callApiUsingWithFixURLGET(directionsUrlString, withLoader: true) { (responceData) -> Void in
        let json = responceData as! NSDictionary
        let routesArray: [AnyObject] = (json["routes"] as! [AnyObject])
        var polyline: GMSPolyline? = nil
        if routesArray.count > 0 {
            let routeDict: [NSObject : AnyObject] = routesArray[0] as! [NSObject : AnyObject]
            var routeOverviewPolyline: [NSObject : AnyObject] = (routeDict["overview_polyline"] as! [NSObject : AnyObject])
            let points: String = (routeOverviewPolyline["points"] as! String)
            let path: GMSPath = GMSPath(fromEncodedPath: points)!
            polyline = GMSPolyline(path: path)
            polyline!.strokeWidth = 2.0
            polyline!.map = self.mapView
        }

    }
}