Search code examples
iosiphonegoogle-mapsgmsmapview

google map marker hide inside the uisearchbar and not display in center of the map


i am using google map api for display the location and search bar for search the location but when the GSMMarker display it snippet window hide inside the uisearchbar so any own please help me.

-(void) setupMarkerOnMap:(CLLocation *)loc PlaceName:(NSString *) strCityName
{
    [[self getGoogleMap] clear];
    [self getNextButton].enabled = YES;
    placeMarker = [GMSMarker markerWithPosition:loc.coordinate];
    placeMarker.map = [self getGoogleMap];
    [placeMarker setTappable:NO];

    placeMarker.snippet = strCityName;
    placeMarker.icon = [UIImage imageNamed:@"LocationMarker.png"];
    GMSCameraUpdate *updateCamera = [GMSCameraUpdate setTarget:placeMarker.position zoom:10.0];
    [[self getGoogleMap] animateWithCameraUpdate:updateCamera];
    [[self getGoogleMap] setSelectedMarker:placeMarker];
}

these my code snippet for marker add in google map and i attached image which can help you. anyone can help me. Thanks


Solution

  • First of all, Make sure that your Google map does not stack together with the search bar. Then you can use delegate to help you move the animate the marker's position inside the Google Map when you tap on any of the marker. Example code:-

    Implement the Google Map Delegate

    @interface YourViewController ()<GMSMapViewDelegate>
    @property (weak, nonatomic) IBOutlet GMSMapView *mapView;
    @end
    

    Set the mapView Delegate to the current view controller

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.mapView.delegate = self;
    }
    

    Whenever a marker is tapped, the

    -(BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker{
        [mapView animateToLocation:marker.position];
        return YES;
    }
    

    If you have everything setup correctly and the map is big enough, info window should be displayed nicely inside the map.