Hello all I am using GoogleMaps to display multiple markers on mapview. Maps is working fine and it display multiple markers according to coordinate. but it it not displaying the title of the location.
I am using the following code:
- (void)viewDidLoad
{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:cityLattitude
longitude:cityLongitude
zoom:7];
[self.mapView animateToCameraPosition:camera];
//GMSMapView *mapView; //= [GMSMapView mapWithFrame:CGRectZero camera:camera];
[mapView animateToCameraPosition:camera];
mapView.indoorEnabled = NO;
mapView.mapType = kGMSTypeNormal;
viewFormap = mapView;
mapView.accessibilityElementsHidden = NO;
mapView.myLocationEnabled = YES;
NSLog(@"User's location: %@", mapView.myLocation);
mapView.delegate = self;
GMSMarker * marker = [[GMSMarker alloc]init];
marker.position = CLLocationCoordinate2DMake(cityLattitude, cityLattitude );
marker.map = mapView;
[mapView animateToCameraPosition:camera];
}
To display annotations i used the following code:
-(void)plotMutliplePinsOnMap//:(NSArray *)MapDataArray { for(int i=0;i<[MapDataArray count];i++) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
// Set label properties as required including marker Name
UIImageView *markerIconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(35, 10, 30, 50)];
// Set image properties as required including image which will be displayed as marker
UIView *markerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
[markerView addSubview:label];
[markerView addSubview:markerIconImageView];
//GMSMapView *mapView = [[GMSMapView alloc]init];
viewFormap = mapView;
latitude = [[[MapDataArray objectAtIndex:i]valueForKey:@"latitude"] doubleValue];
longitude = [[[MapDataArray objectAtIndex:i]valueForKey:@"longitude"] doubleValue];
eventTypeStr = [[MapDataArray objectAtIndex:i]objectForKey:@"is_paid"];
NSString * price = [[MapDataArray objectAtIndex:i] objectForKey:@"evt_price"];
NSString * Mainprice = [NSString stringWithFormat:@"$%@",price];
NSString * name = [[MapDataArray objectAtIndex:i] objectForKey:@"evt_title"];
NSLog(@"Name is %@", name);
for(int i=0;i<[MapDataArray count];i++){
GMSMarker * marker = [[GMSMarker alloc] init];
if ([eventTypeStr isEqualToString:@"0"])
{
NSLog(@"Eventtype Array is %@",eventTypeStr);
NSLog(@"Event Type is %@",eventTypeStr);
marker.icon = [UIImage imageNamed:@"smiley.png"];
marker.position = CLLocationCoordinate2DMake(latitude,longitude);
marker.title = name;
marker.snippet = name;
marker.tappable = YES;
marker.appearAnimation = kGMSMarkerAnimationPop;
//marker.animated = YES;
marker.map = mapView;
[mapView setSelectedMarker:marker];
}
else if ([eventTypeStr isEqualToString:@"1"])
{
NSLog(@"Event Type is %@",eventTypeStr);
//marker.icon = [UIImage imageNamed:@"dollar1.png"];
marker.icon = [self drawText:price inImage:[UIImage imageNamed:@"markertt1.png"]];
marker.position = CLLocationCoordinate2DMake(latitude,longitude);
marker.title = price;
marker.snippet = name;
marker.tappable = YES;
marker.appearAnimation = kGMSMarkerAnimationPop;
//marker.animated = YES;
marker.map = mapView;
[mapView setSelectedMarker:marker];
}
else if ([eventTypeStr isEqualToString:@"2"])
{
NSLog(@"Event Type is %@",eventTypeStr);
marker.icon = [UIImage imageNamed:@"donation.png"];
marker.position = CLLocationCoordinate2DMake(latitude,longitude);
marker.title = name;
marker.snippet = name;
marker.tappable = YES;
marker.appearAnimation = kGMSMarkerAnimationPop;
//marker.animated = YES;
marker.map = mapView;
[mapView setSelectedMarker:marker];
}
}
} }