我正在开发一个应用程序,包括谷歌地图吗?我用geojson绘制国家,我想在点击国家时进行点击操作。
我正在使用swiftui框架进行开发。
我的代码如下:
func updateUIView(_ mapView: GMSMapView, context: Context) {
let path = Bundle.main.path(forResource: "countries", ofType: "json")
let url = URL(fileURLWithPath: path!)
let geoJsonParser = GMUGeoJSONParser(url: url)
geoJsonParser.parse()
for county in countries {
switch county.countryId {
case 2 : drawTurkey(geoJson : geoJsonParser,model : county,mapView : mapView)
case 3 : drawUSA(geoJson : geoJsonParser,model : county,mapView : mapView)
case 4 : drawChina(geoJson : geoJsonParser,model : county,mapView : mapView)
default: drawBrasil(geoJson : geoJsonParser,model : county,mapView : mapView)
}
}
let renderer = GMUGeometryRenderer(map: mapView, geometries: geoJsonParser.features)
renderer.render()
}
And Draw Turkey Metots like this :
func drawTurkey(geoJson : GMUGeoJSONParser,model : CountryGeneralInformationModel,mapView: GMSMapView){
let marker : GMSMarker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: 38.335742 , longitude: 27.123613 )
marker.title = "İzmir"
marker.snippet = "Welcome to İzmir"
marker.map = mapView
for feature in geoJson.features {
if let feature = feature as? GMUFeature {
let properties = feature.properties
if(properties?.first?.value as! String == "TUR"){
feature.style = GMUStyle(styleID: "feat_1", stroke: nil, fill: UIColor(generateColor(effiency : model.effValue)), width: 2, scale: 1, heading: 1, anchor: CGPoint.zero, iconUrl: nil, title: "afdss" , hasFill: true, hasStroke: true)}}
}
}
我的问题是如何检测我点击功能的时间
使用GMSMapView委托函数didTap(在叠加上(。注意:目前我还没有找到将数据附加到渲染的geo-json覆盖上的方法。