【问题标题】:didTapInfoWindowOfMarker on iOS App SwiftiOS App Swift 上的 didTapInfoWindowOfMarker
【发布时间】:2016-05-14 15:23:32
【问题描述】:

现在我的应用在不同的位置有多个标记。如果您点击标记,则会弹出一个小窗口,其中包括标题和 sn-p。我想在窗口中实现一个按钮,或者使信息窗口可点击,因此它可以作为一个按钮来执行功能。所以我在我的 GoogleMapsViewController.swift 中写了这个块:

func mapView(mapView: GMSMapView, didTapInfoWindowOfMarker marker: GMSMarker) {

    print("test")
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("jobDetailVC") as! JobDetailViewController

    if let value = marker.userData as? PFObject {
        vc.name = value.objectForKey("name") as? String
        vc.descriptionF = value.objectForKey("description") as? String
        vc.price = value.objectForKey("price") as? Double
        vc.objectId = value.objectId!
    }
}

我之所以使用:didTapInfoWindowOfMarker,是因为我不知道如何实现它,所以我从谷歌地图上阅读了文档:https://developers.google.com/maps/documentation/ios-sdk/reference/protocol_g_m_s_map_view_delegate-p?hl=es,并认为这是最好的选择。

有没有人成功实现过这个,或者类似的东西?提前感谢您的帮助!

【问题讨论】:

    标签: ios swift google-maps google-maps-api-3


    【解决方案1】:

    您使用didTapInfoWindowOfMarker 函数在您的信息窗口中添加事件是正确的。

    添加地图时,添加:

     mapView_.delegate=self; 
    

    然后使用它来添加点击时infoWindow的事件/功能:

    -(void)mapView:(GMSMapView *)mapView
    didTapInfoWindowOfMarker:(id<GMSMarker>)marker{
    
       //Info window function
    
    }
    

    GitHub 上的示例:

    // when user tap the info window of store marker, show the product list
        func mapView(mapView: GMSMapView!, didTapInfoWindowOfMarker marker: GMSMarker!) {
            let storeMarker = marker as StoreMarker
            performSegueWithIdentifier("productMenu", sender: storeMarker.store)
        }
    

    // when user tap the info window of store marker, pass selected store to the product list controller
        override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            let controller = segue.destinationViewController as ProductMenuController
            controller.store = sender as Store
        }
    

    func mapView(mapView: GMSMapView, didTapInfoWindowOfMarker marker: GMSMarker) {
    
            for location in locations {
                let pollution = location[0]
                if pollution.locationdesc == marker.title {
                    performSegueWithIdentifier(segueIdentifiers.locations, sender: location)
                    break
                }
            }
        }
    

    检查这个相关问题:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 1970-01-01
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多