如何在目标c中显示谷歌地图上的印度地图

时间:2017-02-27 12:08:40

标签: ios objective-c google-maps

我是iOS新手,我在Google地图上展示印度地图时遇到了问题 我的代码就像第一次

 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];

    }

但是当我使用UIView并使用像这样的IBOutlet创建它时

IBOutlet GMSMapView *mapView;

比上面的代码不起作用。如何通过使用上面的坐标首先显示印度地图。提前谢谢!

3 个答案:

答案 0 :(得分:1)

获取当前位置坐标并传递这些摄像机位置

"field_value_factor": {
  "field": "your_date_field",
  "factor": 1,
  "modifier": "none",
  "missing": 1
}

// pragma mark ----:GET Coordinate2D:----

CLLocationCoordinate2D coordinate;
float latitude;
float longitude;

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

答案 1 :(得分: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

答案 2 :(得分: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";