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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15816684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:02:24  来源:igfitidea点击:

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

iosgoogle-mapsinfowindowgoogle-maps-sdk-ios

提问by albeee

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

我是 iOS 开发的新手。这是关于 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?

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

回答by estemendoza

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 setSelectedMarkermethod to show an info window of a marker

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

回答by Rikkles

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

mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];

(note that it's Options, not Option)

(注意是选项,不是选项)

回答by Sourabh Sharma

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

回答by MrMins

swift 3

迅捷 3

self.mapView.selectedMarker = marker

self.mapView.selectedMarker = marker

In the case of swift 3, you can open the snipetusint the selectedMarker

在swift 3的情况下,您可以打开snipetusintselectedMarker

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

回答by xcodedeveloper

mMapView.selectedMarker = marker

mMapView.selectedMarker = 标记

回答by Naresh Reddy M

   // 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 :)

快乐编码:)

回答by Ayush jain

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

--> 无需点击标记即可显示多个 infoWindows。您可以轻松自定义它。

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

}

}

回答by kumarsiddharth123

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

GMSMarkerOptions 已弃用。使用它帮助我在不点击的情况下显示信息窗口 -

func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
    myMapView.selectedMarker = myGMSMarker
}