如何在iOS谷歌地图中显示信息窗口而无需点击标记?

时间:2021-10-26 21:00:15

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.

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

Is there anyway we can show the info window programmatically when the user goes to Custom Map Screen?

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

6 个解决方案

#1


29  

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

mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];

(note that it's Options, not Option)

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

#2


58  

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方法显示标记的信息窗口

#3


9  

Swift 3.0

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

    }

below line is the answer

以下是答案

mapView.selectedMarker=locationMarker

#4


3  

swift 3

迅捷3

self.mapView.selectedMarker = marker

self.mapView.selectedMarker = marker

In the case of swift 3, you can open the snipet usint the selectedMarker

在swift 3的情况下,你可以打开snipet usint selectedMarker

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

#5


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 .

Happy Coding :)

快乐编码:)

#6


1  

mMapView.selectedMarker = marker

mMapView.selectedMarker = marker

#1


29  

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

mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];

(note that it's Options, not Option)

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

#2


58  

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方法显示标记的信息窗口

#3


9  

Swift 3.0

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

    }

below line is the answer

以下是答案

mapView.selectedMarker=locationMarker

#4


3  

swift 3

迅捷3

self.mapView.selectedMarker = marker

self.mapView.selectedMarker = marker

In the case of swift 3, you can open the snipet usint the selectedMarker

在swift 3的情况下,你可以打开snipet usint selectedMarker

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

#5


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 .

Happy Coding :)

快乐编码:)

#6


1  

mMapView.selectedMarker = marker

mMapView.selectedMarker = marker