我是iOS开发的新手。这是关于Google Maps iOS SDK中的标记信息窗口。
据我所知,我们可以使用GMSMarkerOption创建一个带信息窗口的标记。
GMSMarkerOption *myLocationOption = [GMSMarkerOption alloc];
myLocationOption .title = @"My Location";
myLocationOption .snippet = @"Lat:...., Lang:....";
[mapView addMarkerOption:myLocationOption];
根据上面的代码,Marker按预期显示在Map View中。点击标记会在Google地图中显示“我的位置”信息窗口,这很好。
无论如何我们可以在用户进入自定义地图屏幕时以编程方式显示信息窗口吗?
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options];
myLocationOptions.title = @"My Location";
myLocationOptions.snippet = @"Lat:...., Lang:....";
mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];
(注意它是选项,而不是选项)
这在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方法显示标记的信息窗口
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
}
以下是答案
mapView.selectedMarker=locationMarker
迅捷3
self.mapView.selectedMarker = marker
在swift 3的情况下,你可以使用qazxsw poi打开qazxsw poi
如果您以类似的方式创建标记:
snipet
selectedMarker
快乐编码:)
mMapView.selectedMarker = marker
- >它显示多个infoWindows而不点击标记。您可以轻松自定义它。
因为我在0 ..
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
}
GMSMarkerOptions已弃用。使用这个帮助我显示信息窗口而不点击 -
// 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 .