2014-01-24 64 views
0

因此,我在View Controller(ViewControllerX)中創建了一個包含約10個不同標記的Google Map。所有標記都是根據從MySQL數據庫中提取的緯度/經度座標進行放置的。通過segue傳遞GoogleMapsAPI相機更改

現在我還有一個TableView(ViewControllerY),它向用戶顯示附近標記的列表。當他們點擊桌面視圖中的某個位置時,會將它們帶到一個顯示有關位置信息的詳細視圖控制器。也就是說,我在DetailViewController中添加了一個按鈕,名爲「顯示在地圖上」。

當然,當用戶點擊這個按鈕時,我希望它將它們推送到MapView控制器(ViewControllerX)並放大相應的標記。

我覺得這應該很容易,但是這讓我感到非常緊張。這裏是我在我的DetailViewController中使用的segue,以及接收端的代碼(在我的GoogleMapViewController中)。

我的問題:有誰知道我需要什麼樣的代碼到DetailViewController SEGUE & GoogleMapViewController使相機變焦到我組特定的地圖上的座標的內部發生?

DetailViewController.m

- (IBAction)showonMap:(id)sender { 

    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_1" bundle:nil]; 
    UIViewController *initViewController = [storyBoard instantiateViewControllerWithIdentifier:@"GoogleViewController"]; 
    [self.navigationController pushViewController:initViewController animated:YES]; 


    } 

GoogleViewController.m(谷歌地圖)

- (void)viewDidLoad 
{ 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:49.282237 
                  longitude:-123.125966 
            zoom:13]; 

    mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

    self.view = mapView; 

    for (NSDictionary *dictionary in array) { 
     assert([dictionary respondsToSelector:@selector(objectForKey:)]); 

     CLLocationCoordinate2D position = {[[dictionary objectForKey:@"lat"] doubleValue], 
      [[dictionary objectForKey:@"lng"] doubleValue]}; 
      NSLog(@"%f", position.longitude); 

     GMSMarker *ann = [[GMSMarker alloc] init]; 
     ann.title = [dictionary objectForKey:@"Name"]; 
     ann.snippet = [dictionary objectForKey:@"Address1"]; 
     ann.position = position; 
     ann.map = mapView; 


} 

回答

0

我認爲你正在尋找setVisibleMapRect:animated:方法,這將放大到給定MKMapRect

您可以使用功能MKMapRectMake創建MKMapRect,基於標記位置作爲中心以及寬度和高度,具體取決於您希望的縮放級別。

希望它能爲你工作。