如何在iOS中显示信息窗口Google地图不用点击标记?

我是iOS开发新手。 这是关于Google Maps iOS SDK中的标记信息窗口。

我明白,我们可以使用GMSMarkerOption创build一个带有信息窗口的标记。

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

根据上面的代码,Marker按照预期显示在Map视图中。 点击标记在Google地图上显示“我的位置”信息窗口,这是很好的。

无论如何,当用户转到自定义地图屏幕时,我们可以以编程方式显示信息窗口?

 GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options]; myLocationOptions.title = @"My Location"; myLocationOptions.snippet = @"Lat:...., Lang:...."; mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions]; 

(请注意,它是选项,而不是选项)

这在Google地图SDK上已经发生了变化,而且更容易理解:

 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]; 

您现在使用setSelectedMarker方法来显示标记的信息窗口

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 } 

下面是答案

 mapView.selectedMarker=locationMarker 
  // 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 . 

快乐编码:)

迅速3

self.mapView.selectedMarker = marker

在swift 3的情况下,您可以使用snipet打开snipet

如果您以类似于以下方式创build标记:

 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