如何使用 IOS Swift 中的 CollectionView 项过滤 GoogleMapView 上的标记 4
How to filter markers on GoogleMapView using CollectionView items in IOS Swift 4
我在我的 iOS 应用程序中使用了 googleMapView,我通过这样做在随机位置放置标记:
struct location {
let icon: UIImage
let latitude : CLLocationDegrees
let longitude : CLLocationDegrees
}
class MapViewController: UIViewController,GMSMapViewDelegate,CLLocationManagerDelegate {
let locations = [
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.771873, longitude: -119.750724),
location(icon: UIImage(named :"childcare.png")!, latitude: 36.771930, longitude: -119.761352),
location(icon: UIImage(named :"carpentry.png")!, latitude: 36.772243, longitude: -119.774393),
location(icon: UIImage(named :"education.png")!, latitude: 36.772499, longitude: -119.739129),
location(icon: UIImage(named :"plumbing.png")!, latitude: 36.781273, longitude: -119.793848),
location(icon: UIImage(named :"massage.png")!, latitude: 36.781433, longitude: -119.723345),
location(icon: UIImage(named :"childcare.png")!, latitude: 36.781569, longitude: -119.830231),
location(icon: UIImage(named :"security.png")!, latitude: 36.782312, longitude: -119.767465),
location(icon: UIImage(named :"cleaning.png")!, latitude: 36.782933, longitude: -119.814373),
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.783156, longitude: -119.794719),
location(icon: UIImage(named :"carpentry.png")!, latitude: 36.783873, longitude: -119.363839),
location(icon: UIImage(named :"massage.png")!, latitude: 36.784289, longitude: -119.738238),
location(icon: UIImage(named :"education.png")!, latitude: 36.793321, longitude: -119.738920),
location(icon: UIImage(named :"childcare.png")!, latitude: 36.796312, longitude: -119.749201),
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.799893, longitude: -119.798301),
location(icon: UIImage(named :"plumbing.png")!, latitude: 36.803455, longitude: -119.821022),
location(icon: UIImage(named :"massage.png")!, latitude: 36.803953, longitude: -119.873910),
location(icon: UIImage(named :"carpentry.png")!, latitude: 36.804273, longitude: -119.801032),
location(icon: UIImage(named :"plumbing.png")!, latitude: 36.807721, longitude: -119.834747),
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.809213, longitude: -119.749321)]
override func viewWillAppear(_ animated: Bool) {
for location in locations {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(location.latitude,location.longitude)
marker.icon = location.icon
marker.appearAnimation = GMSMarkerAnimation.pop
marker.map = googleMapView
}
}
现在我的 ViewController 中有一个水平 collectionView,其中有具有相应图像和服务名称的服务。
现在,当我单击 collectionView 中的任何项目时,它应该根据我在 collectionView 中选择的服务过滤位置处的图标。
filter your array with location ,
let newArray = locations.filter{[=10=].latitude == "your lattitude"}
我在我的 iOS 应用程序中使用了 googleMapView,我通过这样做在随机位置放置标记:
struct location {
let icon: UIImage
let latitude : CLLocationDegrees
let longitude : CLLocationDegrees
}
class MapViewController: UIViewController,GMSMapViewDelegate,CLLocationManagerDelegate {
let locations = [
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.771873, longitude: -119.750724),
location(icon: UIImage(named :"childcare.png")!, latitude: 36.771930, longitude: -119.761352),
location(icon: UIImage(named :"carpentry.png")!, latitude: 36.772243, longitude: -119.774393),
location(icon: UIImage(named :"education.png")!, latitude: 36.772499, longitude: -119.739129),
location(icon: UIImage(named :"plumbing.png")!, latitude: 36.781273, longitude: -119.793848),
location(icon: UIImage(named :"massage.png")!, latitude: 36.781433, longitude: -119.723345),
location(icon: UIImage(named :"childcare.png")!, latitude: 36.781569, longitude: -119.830231),
location(icon: UIImage(named :"security.png")!, latitude: 36.782312, longitude: -119.767465),
location(icon: UIImage(named :"cleaning.png")!, latitude: 36.782933, longitude: -119.814373),
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.783156, longitude: -119.794719),
location(icon: UIImage(named :"carpentry.png")!, latitude: 36.783873, longitude: -119.363839),
location(icon: UIImage(named :"massage.png")!, latitude: 36.784289, longitude: -119.738238),
location(icon: UIImage(named :"education.png")!, latitude: 36.793321, longitude: -119.738920),
location(icon: UIImage(named :"childcare.png")!, latitude: 36.796312, longitude: -119.749201),
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.799893, longitude: -119.798301),
location(icon: UIImage(named :"plumbing.png")!, latitude: 36.803455, longitude: -119.821022),
location(icon: UIImage(named :"massage.png")!, latitude: 36.803953, longitude: -119.873910),
location(icon: UIImage(named :"carpentry.png")!, latitude: 36.804273, longitude: -119.801032),
location(icon: UIImage(named :"plumbing.png")!, latitude: 36.807721, longitude: -119.834747),
location(icon: UIImage(named :"beautycare.png")!, latitude: 36.809213, longitude: -119.749321)]
override func viewWillAppear(_ animated: Bool) {
for location in locations {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(location.latitude,location.longitude)
marker.icon = location.icon
marker.appearAnimation = GMSMarkerAnimation.pop
marker.map = googleMapView
}
}
现在我的 ViewController 中有一个水平 collectionView,其中有具有相应图像和服务名称的服务。
现在,当我单击 collectionView 中的任何项目时,它应该根据我在 collectionView 中选择的服务过滤位置处的图标。
filter your array with location ,
let newArray = locations.filter{[=10=].latitude == "your lattitude"}