简体   繁体   English

如何在不点击标记的情况下在 iOS 谷歌地图中显示信息窗口?

[英]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,您可以在selectedMarkersnipet处打开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.

相关问题 如何在iOS谷歌地图中显示所有信息窗口而无需点击标记? - How to show all Info window in iOS Google maps without tapping on Marker? Google Maps iOS-点击标记以显示默认的Google路线按钮 - Google Maps iOS - Tapping on Marker to show default google directions button Google Maps在标记信息窗口iOS中显示语音气泡 - Google Maps Showing speechbubble in marker info window iOS Google Maps SDK iOS - 带UIButton的自定义标记信息窗口 - Google Maps SDK iOS - Custom marker info window with UIButton 以编程方式谷歌地图iOS的标记的关闭信息窗口 - Close info window of a marker programmatically google maps iOS 如何以编程方式点击ios谷歌地图标记或显示标记的信息窗口? - How to tap on ios google map marker programatically or show info window of marker? 如何使用AFnetworking图像缓存在iOS Google Maps中刷新标记信息窗口? - How to refresh marker info window in iOS Google maps with AFnetworking Image cache? 如何在ios上添加一个按钮到谷歌地图标记信息窗口? - How can i add a button to google maps marker info window on ios? 谷歌地图ios - 如何始终显示标记信息窗口? - Google map ios - how to keep the marker info window always displayed? 在Google地图上加载标记的自定义信息窗口时,iOS应用程序冻结 - iOS app freezes when loading custom info window for marker on Google Maps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM