如何在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
- ios定期获取我的位置,并设置button来获取我的位置 – 谷歌地图不工作
- 检测Swift中的GMSPolyline?
- 使用Google Maps SDK在地图上绘制错误的多段线
- 以相同的方式在GMSAutocomplete中使用textfield而不是searchbar
- Google Maps Javascript API不响应iOS 10中的触摸事件
- 无法使用Xcode 7和带有Podfile的GoogleMaps将IOS应用上传到iTunes
- UNRESOLVED:协议“https”在libcurl中不受支持或禁用
- 当使用GoogleMaps时,myLocationEnabled在swift上更改为isMyLocationEnabled
- Google Maps iOS SDK和故事板