iOS应用Swift上的didTapInfoWindowOfMarker



现在我的应用程序在不同的位置有多个标记。如果你点击一个标记,会弹出一个小窗口,其中包括一个标题和一个片段。我想在窗口中实现一个按钮,或者使信息窗口可以点击,这样它就可以作为执行函数的按钮。所以我在我的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并认为这是最好的选择。

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

使用didTapInfoWindowOfMarker函数在InfoWindow中添加事件是正确的。

当你添加地图时,添加:

 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
            }
        }
    }

检查此相关问题:

  • 在Google Maps SDK中添加InfoWindow/Marker上的点击事件

相关内容

  • 没有找到相关文章

最新更新