27

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

我了解,我们可以使用 GMSMarkerOption 创建带有信息窗口的标记。

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

[mapView addMarkerOption:myLocationOption];

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

当用户转到自定义地图屏幕时,我们是否可以通过编程方式显示信息窗口?

4

8 回答 8

65

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

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

于 2013-10-10T01:24:14.707 回答
31
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options];
myLocationOptions.title = @"My Location";
myLocationOptions.snippet = @"Lat:...., Lang:....";

mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];

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

于 2013-04-04T17:31:17.863 回答
11

斯威夫特 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
于 2016-10-10T10:57:27.737 回答
3

迅速 3

self.mapView.selectedMarker = marker

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

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

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
于 2017-05-10T00:24:59.877 回答
2
   // 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 .

快乐编码:)

于 2016-03-15T11:38:02.027 回答
2

mMapView.selectedMarker = 标记

于 2018-03-25T11:56:39.180 回答
2

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

func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
    myMapView.selectedMarker = myGMSMarker
}
于 2018-11-27T13:53:13.830 回答
2

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

因为我在 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

}

于 2019-04-06T08:32:57.187 回答