thisチュートリアルの助けを借りて2つの場所間のルートを表示しようとしています。彼らは座標のCSVファイルを使用して、私は座標を取得するためにGoogle APIを使用しています。しかし、結果は全く異なります。 MKPolylineを使用した2つの場所間の描画パス
正しいパスが描画されていないことがわかります。 Plzは私に何かを提案します。
thisチュートリアルの助けを借りて2つの場所間のルートを表示しようとしています。彼らは座標のCSVファイルを使用して、私は座標を取得するためにGoogle APIを使用しています。しかし、結果は全く異なります。 MKPolylineを使用した2つの場所間の描画パス
正しいパスが描画されていないことがわかります。 Plzは私に何かを提案します。
これはあなたにすべての点で可変配列を与える
// http://code.google.com/apis/maps/documentation/utilities/polylinealgorithm.html
//
-(NSMutableArray *)decodePolyLine:(NSString *)encodedStr {
NSMutableString *encoded = [[NSMutableString alloc] initWithCapacity:[encodedStr length]];
[encoded appendString:encodedStr];
[encoded replaceOccurrencesOfString:@"\\\\" withString:@"\\"
options:NSLiteralSearch
range:NSMakeRange(0, [encoded length])];
NSInteger len = [encoded length];
NSInteger index = 0;
NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
NSInteger lat=0;
NSInteger lng=0;
while (index < len) {
NSInteger b;
NSInteger shift = 0;
NSInteger result = 0;
do {
b = [encoded characterAtIndex:index++] - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
NSInteger dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
b = [encoded characterAtIndex:index++] - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
NSInteger dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
lng += dlng;
NSNumber *latitude = [[[NSNumber alloc] initWithFloat:lat * 1e-5] autorelease];
NSNumber *longitude = [[[NSNumber alloc] initWithFloat:lng * 1e-5] autorelease];
// printf("[%f,", [latitude doubleValue]);
// printf("%f]", [longitude doubleValue]);
CLLocation *loc = [[[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]] autorelease];
[array addObject:loc];
}
[encoded release];
return array;
}
...あなたは...デコードに使用すると、応答から得ているポリラインを必要とし、そのためには、Googleのアルゴリズムを必要とします(CLLocationオブジェクトの形で) また、メインポリラインをデコードするだけではありません。受信した各ポリラインとすべてのサブポリラインをデコードしてください。それ以外の場合、方向は適切ではありません。
同じエンコード機能を使用していますが、アプリがクラッシュしています。 NSLiteralSearchの範囲:NSMakeRange(0、[encoded length])];コード化replaceOccurrencesOfString:@ "\\\\" withString:@ "\\"それは働いていますが、正確な結果は得られません。 –
私もこれにいくつかの問題を抱えていました...それは小さな距離からの作業でした... AGRAとデリーの間で、私はデリとトリンバンドラムを使用していましたが、クラッシュしました。だから私はそれが本当にどのように動作するのかわかりません。結局私はGoogleマップを使ってwebviewをロードしました。 :P –
正確に何かを提案できますか?それは道路にプロットしていません –
あなたはあなたのコードでは、この簡単な方法を追加することにより、実線(パス)を追加することができます
-(void)addSolidLine:(CLLocation *)source andDestination:(CLLocation*)destination
{
CLLocationCoordinate2D coordinates[2] = {source.coordinate, destination.coordinate};
MKGeodesicPolyline *geodesicPolylineSolid = [MKGeodesicPolyline polylineWithCoordinates:coordinates count:2];
[self.mapView addOverlay:geodesicPolylineSolid];
}
#pragma mark - map view delegate
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:(MKPolyline *)overlay];
renderer.lineWidth = 1.5f;
renderer.strokeColor = [UIColor greenColor];
renderer.alpha = 50;
return renderer;
}
}
そして、あなたは点線を表示したい場合、あなたはこのmedthod追加することができます。
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:(MKPolyline *)overlay];
renderer.lineDashPattern = @[@2, @5];
renderer.lineWidth = 1.5f;
renderer.strokeColor = [UIColor redColor];
renderer.alpha = 50;
isShowingDottedLine = false;
return renderer;
を私は同じDirection APIを使用してアプリを開発していましたが、それはまだ適切に動作しています。その展開ターゲットは3.2だったので、今度はMKPolylineを使ってiOS4用に再び開発しています。 –
問題はiosではなく、あなたのcsvファイルの作成方法とそれを読んでいる方法です。もう一つのヒントは、MKPolylineを作るために形成されているすべての座標をnslogにヒントします。私はあなたが見るものに驚かれるだろうと確信しています。 – Robin
JSONレスポンスを使用していますか? –