2016-08-05 16 views
0
- (void)loadView { 

// Create a GMSCameraPosition that tells the map to display the 
// coordinate -33.86,151.20 at zoom level 6. 
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:37.551927 
                 longitude:-77.456292 
                  zoom:18]; 
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(37.551709, -77.456510); 
GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
marker.title = @"Hi"; 
marker.map = mapView; 
mapView.settings.myLocationButton = YES; 
mapView.myLocationEnabled = YES; 
self.view = mapView; 

GMSMutablePath *path = [GMSMutablePath path]; 
[path addCoordinate:CLLocationCoordinate2DMake(37.552243, -77.457415)]; 
[path addCoordinate:CLLocationCoordinate2DMake(37.551054, -77.455443)]; 

GMSPolyline *polyline = [GMSPolyline polylineWithPath:path]; 
int x = 0; 
if ((x = 1)){ 
    polyline.spans = @[[GMSStyleSpan spanWithColor:[UIColor redColor]]]; 
} 
else polyline.spans = @[[GMSStyleSpan spanWithColor:[UIColor greenColor]]]; 
polyline.strokeWidth = 10.f; 
polyline.map = mapView;} 

条件に基づいてこのポリラインの色を変更しようとしています。私はXCodeを初めて使うので、if文を試しましたが、なんらかの理由で動作しません。任意のアイデアをいただければ幸いです!ポリラインの色を条件付きで変更する

答えて

0

割り当て演算子と比較演算子を混在させました。

= - >新しい値を代入
== - >左と右の値は、あなたのために残念ながら

等しいかどうかを確認、それは別の何かを意味しますが、それは、まだ有効な「条件付き」の文です。

if (x = 1)

- x1

に等しい>場合 - 割り当てが成功した場合>
if (x == 1)xの値が考慮される。すなわち trueします)
関連する問題