我是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地图中的“我的位置”信息窗口,这很好。
当用户进入自定义地图屏幕时,我们是否可以以编程方式显示信息窗口?
答案 0 :(得分:60)
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 方法显示标记的信息窗口
答案 1 :(得分:31)
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options];
myLocationOptions.title = @"My Location";
myLocationOptions.snippet = @"Lat:...., Lang:....";
mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions];
(请注意,它是选项,而不是选项)
答案 2 :(得分:9)
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 :(得分:3)
swift 3
self.mapView.selectedMarker = marker
对于swift 3,您可以打开snipet
usint selectedMarker
如果您以类似的方式创建标记:
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
答案 4 :(得分: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 .
快乐编码:)
答案 5 :(得分:1)
mMapView.selectedMarker = marker
答案 6 :(得分:1)
GMSMarkerOptions已弃用。使用此功能,我无需点击即可显示信息窗口-
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
myMapView.selectedMarker = myGMSMarker
}
答案 7 :(得分:1)
->它显示多个infoWindows,而无需点击标记。您可以轻松地对其进行自定义。
对于0中的i。
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
}
答案 8 :(得分:0)
对于那些使用MKMapView
登陆这里的人
mkMapView.selectedAnnotations = [annotation]