且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将谷歌地图分配给自定义视图

更新时间:2022-12-11 11:38:18

在您的项目中试试这个:

Try this in your project:

//
//  testViewController.m
//  maps
//
//  Created by Millén on 2013-02-25.
//  Copyright (c) 2013 JamWeb. All rights reserved.
//

#import "testViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@interface testViewController ()
@property(nonatomic, strong) GMSMapView *gMapView;
@end

@implementation testViewController {
    CLLocation *oldLocation;
}

-(void)loadView
{
    CLLocationDegrees lat = 59.34702;
    CLLocationDegrees lon = 18.04053;

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lat longitude:lon zoom:10];
    self.gMapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    self.gMapView.myLocationEnabled = YES;
    self.view = self.gMapView;

    [self updateLocation];
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Start locationmanager
    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];


}

- (IBAction)updateLocation {
    [locationManager startUpdatingLocation];
}



- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locations lastObject];

    /*
    if(!oldLocation)
    {
        oldLocation = location;
    }

    if (![location isEqual:oldLocation]) {
        GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: location.coordinate.latitude
                                                                longitude: location.coordinate.longitude
                                                                     zoom:7];

        mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
        mapView_.myLocationEnabled = YES;
        self.view = mapView_;

        oldLocation = location;
        [locationManager stopUpdatingLocation];
    }
     */



    NSLog(@"lat%f - lon%f", location.coordinate.latitude, location.coordinate.longitude);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end