2017-01-23 4 views
0

道路に接続していない2つの目的地間にカスタムルートを描画するにはどうすればよいですか? ソースはピザ工場で、は、ATIのソリューションである場合iOSのGoogleマップでカスタムルートを描く

は例えば、私はこのようなルートを描画する必要がなく、これら二つの場所を接続する道路がありません。

enter image description here

私はGoogleのポリラインコードを試みたが、それが唯一の道でウェイポイントを提供します。

NSString *urlString = [NSString stringWithFormat:@"%@?origin=%@,%@&destination=%f,%f&sensor=false&waypoints=optimize:true&mode=driving", @"https://maps.googleapis.com/maps/api/directions/json", getmycurrlat, getmycurrlong, LATI, LONGI]; 
    NSLog(@"my driving api URL --- %@", urlString); 
    NSLog(@"you clicked on button %ld", (long)sender.tag); 
    NSURL* url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@", urlString]]; 
    NSURLResponse* res; 
    NSError* err; 
    NSData* data = [NSURLConnection sendSynchronousRequest:[[NSURLRequest alloc] initWithURL:url] returningResponse:&res error:&err]; 
    if (data == nil) { 
     return; 
    } 

    NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
    NSDictionary* routes = [dic objectForKey:@"routes"][0]; 
    NSDictionary* route = [routes objectForKey:@"overview_polyline"]; 
    NSString* overview_route = [route objectForKey:@"points"]; 

    GMSPath* path = [GMSPath pathFromEncodedPath:overview_route]; 
    GMSPolyline* polyline = [GMSPolyline polylineWithPath:path]; 
    polyline.strokeWidth = 5.f; 
    polyline.map = self.mapView; 

すべてのサポートがありがとうございます。

+0

マップ好適標準的な方法は、カスタムの種類、離れて渡すために適切なスペースを持つ道路上にあるデータを取得するためにAFNetworkingを使用しています、あなたの役に立てば幸い、これは私のための作品で試してみてくださいあなたが作りたいルート? – vaibhav

+0

ピザ工場とATIソリューションを結ぶ道はありません。2つの建物の間にはスペースしかありません。スナップショットのような行を描く方法はありますか? –

+0

私のエクスプレスマップでは、静的 'lat'' long'を前に提供する場合にのみ、接続された道路上のルートを作成しますが、動いている間には、ソースをdestに賭けるための動的方法もあります(http:// stackoverflow。 com/questions/18422826/how-to-track-a-users-location-and-display-the-travel-traveling-go-google-mapsを使用して) – vaibhav

答えて

0

それは私が敗走を作るために

NSString *url1 = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/directions/json?&origin=%@&destination=%@&mode=driving",[NSString stringWithFormat:@"%f,%f",self.locationManager.location.coordinate.latitude,self.locationManager.location.coordinate.longitude],pickLoc]; 
    AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager]; 
    [operationManager POST:url1 
       parameters: nil 
        success:^(AFHTTPRequestOperation *operation, id responseObject) { 
         // NSLog(@"JSON: %@", [responseObject description]); 

         NSArray *routesArray = [responseObject objectForKey:@"routes"]; 

         GMSPolyline *polyline = nil; 

         if ([routesArray count] > 0) 
         { 
          NSDictionary *routeDict = [routesArray objectAtIndex:0]; 
          NSDictionary *routeOverviewPolyline = [routeDict objectForKey:@"overview_polyline"]; 
          NSString *points = [routeOverviewPolyline objectForKey:@"points"]; 
          GMSPath *path = [GMSPath pathFromEncodedPath:points]; 
          polyline = [GMSPolyline polylineWithPath:path]; 
          polyline.strokeWidth = 3; 
          polyline.strokeColor = [UIColor colorWithRed:0.9607 green:0.0358 blue:0.1529 alpha:0.6]; 
          polyline.map = self.viewMapView; 
         } 
        } 
        failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
         NSLog(@"Error: %@", [error description]); 
        } 
    ]; 
+0

これは道路上にポリラインを描画します。しかし、私は非道路区域にポリラインを描画する必要があります。 –

+0

あなたはroutsArrayを見ることができ、独自のカスタムlatをあなたのルートごとに長く設定し、ポリラインを作成する –

+0

ルート配列は道路のウェイポイントだけを提供します。しかし、私は道路以外の道が必要です。上記の画像を確認してください。 –

関連する問題