2017-02-27 4 views
0

私はiOSで新しく、私はGoogleマップ上に複数のピンを作成するという問題に直面しています。 私のコードはGoogle Mapsで目的のCで複数のピンを動的に作成する方法

//Google Maps... 

    _placesClient = [GMSPlacesClient sharedClient]; 


    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726 
                  longitude:73.856255 
                   zoom:3]; 
    mapView = [GMSMapView mapWithFrame:CGRectMake(10, 140, 350, 350) camera:camera]; 

    GMSMutablePath *path = [GMSMutablePath path]; 
    [path addLatitude:18.516726 longitude:73.856255]; // Sydney 
    [path addLatitude:19.0728300 longitude:72.8826100]; // Fiji 

    mapView.delegate=self; 
    mapView.myLocationEnabled=YES; 
    locationtbl.hidden=YES; 

    if (nil == locationManager) 
     locationManager = [[CLLocationManager alloc] init]; 

    locationManager.delegate = self; 
    //Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest 
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; 

    // Set a movement threshold for new events. 
    locationManager.distanceFilter = 500; // meters 

    [locationManager startUpdatingLocation]; 

    mapView.settings.myLocationButton = YES; 
    mapView.settings.scrollGestures = YES; 
    mapView.settings.zoomGestures = YES; 
    mapView.settings.tiltGestures=YES; 
    mapView.settings.rotateGestures=NO; 
    mapView.settings.compassButton = YES; 

    [self.view addSubview:mapView]; 

Googleのデリゲートメソッドは、Googleマップ上に複数のピンを表示する方法にある私が問題に直面しています。この

#pragma mark - Google Maps 

// Add a UIButton in Interface Builder to call this function 
    - (IBAction)pickPlace:(UIButton *)sender { 

     CLLocationCoordinate2D center = CLLocationCoordinate2DMake(18.516726, 73.856255); 
     CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, 
                     center.longitude + 0.001); 
     CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, 
                     center.longitude - 0.001); 
     GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast 
                      coordinate:southWest]; 
     GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport]; 
     _placePicker = [[GMSPlacePicker alloc] initWithConfig:config]; 

     [_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) { 
      if (error != nil) { 
       NSLog(@"Pick Place error %@", [error localizedDescription]); 
       return; 
      } 

      if (place != nil) { 
       self.nameLabel.text = place.name; 
       self.addressLabel.text = [[place.formattedAddress 
              componentsSeparatedByString:@", "] componentsJoinedByString:@"\n"]; 
      } else { 
       self.nameLabel.text = @"No place selected"; 
       self.addressLabel.text = @""; 
      } 


}]; 
} 

のようなものです)を表示DidLoadでこの

(のようなものです。私は動的である配列のWebサービスから価値を得ています。この画像のように、enter image description hereをGoogleマップに表示する必要があります

Hは、Googleマップで作成されたピンです。これはどのように行うのですか?

私はこの

for (int i=0; i<NameHSArray.count; i++) { 
       CLLocationCoordinate2D position = CLLocationCoordinate2DMake(18.516726, 73.856255); 
       GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
       marker.title = @"Hello World"; 
       marker.icon = [UIImage imageNamed:@"mapicon1.png"]; 
       marker.map = mapView; 

      } 

のようなコードを使用しかし、私はそれは私が事前に

enter image description here

感謝をエラー与える配列を追加していたときに!

私はこのコードを使用し、その

[mapView clear]; // remove all 

marker.mapView = nil // remove specific 

に従うよう、あなたがのMapViewからマーカーを削除することができGMSMapView

GMSMarker *marker = [[GMSMarker alloc] init]; 
marker.position = CLLocationCoordinate2DMake([lat doubleValue], [lng doubleValue]); 
marker.title = "" // you can set marker title here 
marker.icon = [UIImage imageNamed:@"gasoline-pump.png"]; // you can set your image here 
marker.snippet = "" // you can set snippet for more details 
marker.tracksViewChanges = YES; 
marker.tracksInfoWindowChanges = YES; 
marker.infoWindowAnchor = CGPointMake(5, 2); 
marker.map = mapView; 

にマップピンを追加するためにこれを試して

for (int i=0; i<NameHSArray.count; i++) { 
       double LatitudeDouble = [LatitudeHSArray[i] doubleValue]; 
       double LongitudeDouble = [LongitudeHSArray[i] doubleValue]; 
       CLLocationCoordinate2D position = CLLocationCoordinate2DMake(LatitudeDouble, LongitudeDouble); 
       GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
       marker.title = NameHSArray[i]; 
       marker.icon = [UIImage imageNamed:@"mapicon1.png"]; 
       GMSCameraUpdate *zoomCamera = [GMSCameraUpdate zoomIn]; 
       [mapView animateWithCameraUpdate:zoomCamera]; 
       marker.map = mapView; 

      } 
+0

文字列値をデフォルトたい場合は、1 ...かnilを持っている場合、Nは、それと緯度の長い位置を通過し、アイコンイメージを割り当てます配列でこれを試してみてください[[LattitudeHSArray objectAtIndex:0] doubleValue] 配列内のdouble値を使用し、[LattitudeHSArray objectAtIndex:0]を使用してください これを試してください –

答えて

1

を行って - - EDIT ----

あなたはGMSMarkerオブジェクトを作成することによって、複数のピンまたはアイコンを作成することができます従う

for (obj in <#your array#>) { 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake([lat doubleValue], [lng doubleValue]); 
    marker.title = "" // you can set marker title here 
    marker.icon = [UIImage imageNamed:@"gasoline-pump.png"]; // you can set your image here 
    marker.snippet = "" // you can set snippet for more details 
    marker.tracksViewChanges = YES; 
    marker.tracksInfoWindowChanges = YES; 
    marker.infoWindowAnchor = CGPointMake(5, 2); 
    marker.map = mapView; 
} 
+0

私のlatとlngは配列形式です。 – Muju

+0

複数のマーカーにループを使用することができます –

+0

どうすればよいですか? – Muju

0

として、複数のマーカーを設定します。あなたは1つの

を割り当て、GMSMapViewオブジェクトにそのマーカーオブジェクトを追加する

GMSMarker *marker = [[GMSMarker alloc] init]; 
marker.position = CLLocationCoordinate2DMake([lat doubleValue], [lng doubleValue]); 

marker.icon = nil; 
marker.map = mapView; // object of GMSMapView 
関連する問題