2

I have to add a custom label on Marker pin of Google maps in IOS.

I have already implemented markerInfoWindow method. But it works after i tapped on marker/Pin.

I need to show custom label at start as long as mapview will load on view without performing any action. As we can set icon or title on the marker, I need to show my own Custom view on it.

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {

CLLocationCoordinate2D anchor = marker.position;

   // CGPoint point = [mapView.projection pointForCoordinate:anchor];

   // self.calloutView.title = marker.title;
    [self.calloutView setFrame:CGRectMake(0, 50, 25, 25)];
    self.calloutView.layer.cornerRadius = 11.0;
    self.calloutView.layer.masksToBounds = YES;
    self.calloutView.layer.borderColor = [UIColor clearColor].CGColor;
    self.calloutView.layer.borderWidth = 0.0;
    self.calloutView.hidden = NO;

    return self.calloutView;
}
James Z
  • 12,209
  • 10
  • 24
  • 44
  • have you found the answer? – Shehbaz Khan Apr 06 '15 at 06:11
  • @anshul-systematix Have you solved this problem? I am hitting the same issue as you. But if my understanding of your question is correct, it seems to me that the answers given are not exactly what you want. At least they are not the answer I am looking for. I want to be able to display some information on a few pins(GMSMarker) without simulating a hit on the pin and moving it around. I just want to make the information appear at the same time as the pin. If that was also what you wanted, maybe you know the answer? – Michel Dec 29 '16 at 01:58
  • You can use a UIImage for the icon, based on a label, however it uses quite a lot of Memory: https://stackoverflow.com/questions/43910085/googlemaps-sdk-for-ios-swift-3-when-hiding-a-marker-and-then-adding-the-map-v – Efren Jul 13 '17 at 05:45

2 Answers2

1

Use this code to add an image for GMSMarker:

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = MARKER_POSITION;
marker.infoWindowAnchor = CGPointMake(0.44f, 0.45f);
marker.icon = [UIImage imageNamed:@"CustomMarkerImageName"];

You can also use this delegate method to provide custom view for additional info:

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  InfoWindow *view =  [[[NSBundle mainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];
  view.name.text = @"Place Name";
  view.description.text = @"Place description";
  view.phone.text = @"123 456 789";
  view.placeImage.image = [UIImage imageNamed:@"customPlaceImage"];
  view.placeImage.transform = CGAffineTransformMakeRotation(-.08);
  return view;
}

Check this answer as a reference: https://stackoverflow.com/a/16767124/2082569

Community
  • 1
  • 1
atulkhatri
  • 10,896
  • 3
  • 53
  • 89
1

If I understand correctly, the ask is to show the info window for a particular marker programmatically.

[self.mapView setSelectedMarker:marker];

To achieve camera refocus similar to if a user had tapped the marker, do something like:

GMSCameraPosition *cameraPosition =
[[GMSCameraPosition alloc] initWithTarget:marker.position
                                     zoom:15
                                  bearing:0
                             viewingAngle:0];
[self.mapView animateToCameraPosition:cameraPosition];
Tom Howard
  • 4,672
  • 2
  • 43
  • 48