2017-02-27 25 views
1

我在iOS的新的和我面对关于显示印度在谷歌地图中的地图问题 我的代码是这样的第一如何显示印度地图上谷歌地图的目标C

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726 
                  longitude:73.856255 
                   zoom:3]; 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     //Scrollview 
     mapView = [GMSMapView mapWithFrame:CGRectMake(10, 140, 750, 350) camera:camera]; 
    } 
    else 
    { 
     //Scrollview 
     mapView = [GMSMapView mapWithFrame:CGRectMake(10, 140, 550, 350) camera:camera]; 

    } 

但是当我使用它使用IBOutlet中这样

IBOutlet GMSMapView *mapView; 

比上面的代码,我不work.How可以先显示出印度地图使用上述提前coordinate.Thanks的UIView和创造!

+0

当您已经在故事板中创建了框架时,您无需创建框架。你为什么要创建框架? – Priyal

+0

你正在创建一个属性?请出示你的故事板。 – Priyal

+0

@Priyal我需要添加像这样的摄像头值mapView = [GMSMapView mapWithFrame:CGRectMake(10,140,750,350)camera:camera];我正在使用.xib – Muju

回答

1

获取当前位置的坐标和这些相机位置传递

CLLocationCoordinate2D coordinate; 
float latitude; 
float longitude; 

coordinate = [self getLocation]; 
latitude = coordinate.latitude; 
longitude = coordinate.longitude; 

//编译标志----:GET Coordinate2D:----

-(CLLocationCoordinate2D) getLocation 
{ 
    CLLocation *location = [_locationManager location]; 
    coordinate = [location coordinate]; 
    return coordinate; 
} 

    CGRect frame = CGRectMake(0, 0, kSCREEN_WIDTH,kSCREEN_HEIGHT); 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude longitude:longitude zoom:12]; 
    mapView_ = [GMSMapView mapWithFrame:frame camera:camera]; 
    mapView_.myLocationEnabled = YES; 
    mapView_.delegate = self; 

[mapView_ setCamera:camera]; 
+0

你能请告诉我听到什么是框架? – Muju

+0

请仔细编辑CGRect frame = CGRectMake(0,0,kSCREEN_WIDTH,kSCREEN_HEIGHT); –

+0

我刚刚使用你的代码[mapView setCamera:camera];并完成。感谢帮助。 – Muju

0

下面是一个示例代码:

#import <GoogleMaps/GoogleMaps.h> 

@interface ViewController()<GMSMapViewDelegate> 
{ 
    GMSMapView *mapView; 
    GMSMarker *marker; 
} 
@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self showMarker];  
} 

- (void)showMarker 
{ 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726 longitude:73.856255 zoom:3]; 
    mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; 
    [self.view addSubview:mapView]; 
} 

@end 
0

试试这个代码:

@interface ViewController()<GMSMapViewDelegate> 
{ 

    GMSMapView *mapView_; 
} 


GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726 
                    longitude:73.856255 
                     zoom:3]; 

      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
      { 
       //Scrollview 
       mapView_ = [GMSMapView mapWithFrame:CGRectMake(10, 140, 750, 350) camera:camera]; 
      } 
      else 
      { 
       //Scrollview 
       mapView_ = [GMSMapView mapWithFrame:CGRectMake(10, 140, 550, 350) camera:camera]; 

      } 


       NSError *error; 

      // Set the map style by passing a valid JSON string. 
      GMSMapStyle *style = [GMSMapStyle styleWithJSONString:kMapStyle error:&error]; 

      if (!style) { 
       NSLog(@"The style definition could not be loaded: %@", error); 
      } 
      mapView_.mapStyle = style; 
      mapView_.mapType = kGMSTypeNormal; 

      [self.scrllView addSubview:mapView_]; 


      [_btnMap setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal]; 

      mapView_.delegate = self; 


      CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
                     18.516726, 
                     73.856255); 


      GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
      marker.map = mapView_; 
      marker.icon=[UIImage imageNamed:@"locationBlue"]; 
      marker.title = @"From";