[英]How to show a Info window in iOS Google maps without tapping on Marker?
I am new to iOS development.我是 iOS 开发的新手。 This is regarding Marker info window in Google Maps iOS SDK.
这是关于 Google Maps iOS SDK 中的标记信息窗口。
I understand, we can create a marker with info window using GMSMarkerOption.我明白,我们可以使用 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?无论如何,当用户转到自定义地图屏幕时,我们可以以编程方式显示信息窗口吗?
This has changed on Google Maps SDK and it's easier to understand: 这在Google Maps 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];
You use now setSelectedMarker method to show an info window of a marker 您现在使用setSelectedMarker方法显示标记的信息窗口
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options];
myLocationOptions.title = @"My Location";
myLocationOptions.snippet = @"Lat:...., Lang:....";
mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];
(note that it's Options, not Option) (请注意,它是选项,而不是选项)
Swift 3.0 斯威夫特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
swift 3 迅捷3
self.mapView.selectedMarker = marker
In the case of swift 3, you can open the snipet
usint the selectedMarker
对于
snipet
3,您可以在selectedMarker
的snipet
处打开snipet
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
// 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 :) 快乐编码:)
mMapView.selectedMarker =标记
--> It shows multiple infoWindows without tapping on marker. ->它显示多个infoWindows,而无需点击标记。 You can easily customise it.
您可以轻松地对其进行自定义。
for i in 0.. 为我在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
} }
GMSMarkerOptions is deprecated. 不建议使用GMSMarkerOptions。 Using this helped me to show info window without tapping-
使用此功能,我无需点击即可显示信息窗口-
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
myMapView.selectedMarker = myGMSMarker
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.