2014-01-24 60 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,基于标记位置作为中心以及宽度和高度,具体取决于您希望的缩放级别。

希望它能为你工作。