How to show a Info window in iOS Google maps without tapping on Marker?
Asked Answered
A

8

27

I am new to iOS development. This is regarding Marker info window in Google Maps iOS SDK.

I understand, we can create a marker with info window using GMSMarkerOption.

GMSMarkerOption *myLocationOption = [GMSMarkerOption alloc];
myLocationOption .title = @"My Location";
myLocationOption .snippet = @"Lat:...., Lang:....";

[mapView addMarkerOption:myLocationOption];

As per the above code, Marker displayed in the Map View as expected. And tapping on marker shows the "My Location" info window in Google maps which is good.

Is there anyway we can show the info window programmatically when the user goes to Custom Map Screen?

Auston answered 4/4, 2013 at 16:29 Comment(0)
R
31
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options];
myLocationOptions.title = @"My Location";
myLocationOptions.snippet = @"Lat:...., Lang:....";

mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];

(note that it's Options, not Option)

Runthrough answered 4/4, 2013 at 17:31 Comment(0)
S
65

This has changed on Google Maps SDK and it's easier to understand:

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = coordinate;
marker.title = @"Location selected";
marker.snippet = @"Testing";
marker.map = mapView_;

//Show info window on map
[mapView_ setSelectedMarker:marker];

You use now setSelectedMarker method to show an info window of a marker

Spill answered 10/10, 2013 at 1:24 Comment(3)
i used above code but infowindow only displayed when i tapped on marker.is there anyway to showing infowindow and pin simultaneously??Bonnie
@BandishDave, the code above should do what you're looking for. If not, maybe something changed on the SDK againSpill
@BandishDave - setSelectedMarker still works as of 12/26/14 (SDK v1.9.1).Hoofbound
R
31
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options];
myLocationOptions.title = @"My Location";
myLocationOptions.snippet = @"Lat:...., Lang:....";

mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];

(note that it's Options, not Option)

Runthrough answered 4/4, 2013 at 17:31 Comment(0)
R
11

Swift 3.0

func addMarker(_ location:CLLocation){
        var locationMarker: GMSMarker!
        if locationMarker != nil {
            locationMarker.map = nil
        }
        locationMarker = GMSMarker(position: location.coordinate)
        locationMarker.map = mapView
        locationMarker.appearAnimation = kGMSMarkerAnimationPop
        locationMarker.icon = GMSMarker.markerImage(with: UIColor.green)
        locationMarker.opacity = 0.85
        locationMarker.isFlat = true
        locationMarker.snippet = "My Location"
        mapView.selectedMarker=locationMarker

    }

below line is the answer

mapView.selectedMarker=locationMarker
Residence answered 10/10, 2016 at 10:57 Comment(0)
O
3

swift 3

self.mapView.selectedMarker = marker

In the case of swift 3, you can open the snipet usint the selectedMarker

If you are creating the marker in a similar way to:

marker.position = CLLocationCoordinate2D(latitude: 34.1331168, longitude: -118.3550723)
marker.title = "My super place name"
marker.snippet = "Are you looking a place to play? This is your place! "
marker.appearAnimation = kGMSMarkerAnimationPop
marker.map = self.mapView
Ockeghem answered 10/5, 2017 at 0:24 Comment(0)
S
2
   // Below line will shows the infowindow for marker with out tapping on it
   [mapView setSelectedMarker:myLocationOptions]; // myLocationOptions is your desired GMSMarker to show Infowindow with out tapping .

Happy Coding :)

Sulfide answered 15/3, 2016 at 11:38 Comment(0)
C
2

mMapView.selectedMarker = marker

Corbitt answered 25/3, 2018 at 11:56 Comment(0)
A
2

GMSMarkerOptions is deprecated. Using this helped me to show info window without tapping-

func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
    myMapView.selectedMarker = myGMSMarker
}
Assimilative answered 27/11, 2018 at 13:53 Comment(0)
S
2

--> It shows multiple infoWindows without tapping on marker. You can easily customise it.

for i in 0..

        let dict = arrNearByPlacesArray.object(at: i) as? NSDictionary ?? [:]

        let lat = dict.object(forKey: "latitude") as? String ?? ""
         let long = dict.object(forKey: "longitude") as? String ?? ""
        let company_id = dict.object(forKey: "company_id") as? String ?? ""
        let totaljobs = dict.object(forKey: "totaljobs") as? String ?? ""


        let location = CLLocationCoordinate2D(latitude: Double(lat) ?? 0.0, longitude: Double(long) ?? 0.0)
        print("location: \(location)")
        let marker = GMSMarker()
        //marker.icon = UIImage(named: "maps")

        let viewData = Bundle.main.loadNibNamed("MarkerXibView", owner: self, options: nil)?.first as! MarkerXibView .      //UIView


        marker.iconView = viewData .      //UIView


        marker.position = location
        marker.accessibilityLabel  = company_id
        marker.map = vwGoogleMap

}

Stern answered 6/4, 2019 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.