2017-02-27 1 views
0

저는 iOS에서 새로운 기능이며 Google지도에서 여러 핀을 만드는 것과 관련하여 문제가 있습니다. 내 코드객관적인 C에서 Google지도에 동적으로 여러 개의 핀을 만드는 방법

//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지도에 여러 개의 핀을 표시하는 방법이다 내가 문제를 직면하고이

#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이

(과 같다. 동적 인 배열의 웹 서비스에서 가치를 얻고 있습니다. 이 이미지와 같이 Google지도에 enter image description here을 표시해야합니다.

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

감사 오류 줘!

은이 코드를 사용하고는

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

문자열 값에 해당 마커 개체를 추가 할 하나를 기본하려는 경우와 위도 긴 위치를 전달하고 하나가있는 경우 아이콘 이미지를 할당 ... 또는 전무 배열에서 이것을 시도해보십시오 [[LattitudeHSArray objectAtIndex : 0] doubleValue] 배열에 double 값을 입력 한 다음 [LattitudeHSArray objectAtIndex : 0]을 사용하십시오 이것을 시도하십시오 –

답변

1

[mapView clear]; // remove all 

marker.mapView = nil // remove specific 

에 따라 당신이지도보기에서 마커를 제거 할 수 있습니다 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 (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

당신은 GMS 마커 객체를 생성하여 여러 핀 또는 아이콘을 만들 수 있습니다 따를설정 여러 마커. N 당신이

를 할당하고 GMSMapView의 개체

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

marker.icon = nil; 
marker.map = mapView; // object of GMSMapView 
관련 문제