2016-05-14 28 views
0

現在我的應用在不同位置上有多個標記。如果你點擊一個標記,會彈出一個小窗口,其中包括一個標題和一個片段。我想在窗口中實現一個按鈕,或者使信息窗口可點擊,因此它可以作爲執行功能的按鈕。所以我在寫GoogleMapsViewController.swift此塊:iOS應用上的didTapInfoWindowOfMarker 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,並認爲這是最好的選擇。

有沒有人成功地實現了這個,或類似的東西?先謝謝您的幫助!

回答

2

您正確使用didTapInfoWindowOfMarker函數在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) 
    } 
點擊時

mapView_.delegate=self; 

然後用它來添加信息窗口的事件/功能


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

入住此相關的問題:

相關問題