2017-03-15 6 views
1

私はGMSPolygon * polygon = [GMSPolygon polygonWithPath:rect]を試しています。メソッドによって、ユーザがタップした座標のポリゴンを描画します。ここで私がクリックされた座標保存方法は次のとおりです。この後long/lat値に基づいてポリゴンを描画するための配列値の挿入方法 - Google Maps iOS?

// array made of clicked coordinates 
NSMutableArray *latitudeTappedCoordinates = [NSMutableArray array]; 
NSMutableArray *longitudeTappedCoordinates = [NSMutableArray array]; 
NSUInteger numberOfLongitudeCoordinates = [longitudeTappedCoordinates count]; 
NSUInteger numberOfLatitudeCoordinates = [latitudeTappedCoordinates count]; 
for (int i = 2; i < numberOfLatitudeCoordinates; i++) { 
    [latitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.latitude]]; 
} 
for (int i = 2; i < numberOfLongitudeCoordinates; i++) { 
    [longitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.longitude]]; 
} 

を、私は次のようしている:

// polygon 
GMSMutablePath *rect = [GMSMutablePath path]; 
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; 
GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect]; 

あなたが見ることができるように、ライン

[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; 

は、単一の属性になります。上記の配列initのすべての値を取り込んで、ポリゴンを描くことができます。どうやってやるの?

答えて

1

int値ではないファーストストアのfloat値が配列に格納されます。その後、

あなたはこのように行うことができますインターフェイスで

NSMutableArray *latitudeTappedCoordinates; 
NSMutableArray *longitudeTappedCoordinates; 

を追加します。

// Create a rectangular path 
GMSMutablePath *rect = [GMSMutablePath path]; 
CLLocationCoordinate2D event; 

for (int i = 0; i <= [longitudeTappedCoordinates count]-1; i++) { 
    event.latitude = [[latitudeTappedCoordinates objectAtIndex:i] floatValue]; 
    event.longitude = [[longitudeTappedCoordinates objectAtIndex:i] floatValue]; 
    [rect addCoordinate:event]; 
} 

GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect]; 
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05]; 
polygon.strokeColor = [UIColor blackColor]; 
polygon.strokeWidth = 2; 
polygon.map = mapView; 
+0

この私が得たエラーです:終了アプリによるキャッチされない例外に 'NSRangeException'、理由:「* ** - [__ NSArrayM objectAtIndex:]:空の配列の境界を超えるインデックス0 – konyv12

+0

int i = 0をint i = 1に初期化して固定しました。 – konyv12

+0

ただし、コードは機能しません。なぜどんなアイデア?私はマーカーを追加し続けますが、ポリゴンは描画されません。 – konyv12

関連する問題