Google Directions API の使用に問題があります。JSON 文字列を取得して解析し、overview_polylines 文字列を取得しています
NSString *allPolylines = [NSString stringWithFormat:[[[routes objectAtIndex:0] objectForKey:@"overview_polyline"] objectForKey:@"points"]];
これは機能します。マップに追加できなくて困っています。私はこの投稿http://iosguy.com/tag/directions-api/を使用しています。これはまさに私が求めているものと思われます。
私は実装しました
-(NSMutableArray *)decodePolyLine:(NSString *)encodedStr
メソッド、そしてそれはうまくいきます。結果を NSLogged すると、CLLocation オブジェクトを出力しているかのように表示されます。
問題は、マップに表示できないことです。これは次のコードです
NSMutableArray *_path = [self decodePolyLine:allPolylines];
NSInteger numberOfSteps = _path.count;
CLLocationCoordinate2D coordinates[numberOfSteps];
for (NSInteger index = 0; index < numberOfSteps; index++) {
CLLocation *location = [_path objectAtIndex:index];
CLLocationCoordinate2D coordinate = location.coordinate;
coordinates[index] = coordinate;
}
MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
[_mapView addOverlay:polyLine];
[self mapView:_mapView viewForOverlay:polyLine];
また、明示的な呼び出しを追加しようとしました
[self mapView:_mapView viewForOverlay:polyLine];
つまり:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 1.0;
return polylineView;
}
最後のメソッドが呼び出され、NSLog を使用して確認しましたが、マップには何も表示されません。
何かご意見は?前もって感謝します!