私は iOS プログラミングが初めてで、iOS 用の Google マップ SDK をダウンロードし、Web サイトの指示に従いました (このリンク https://developers.google.com/maps/documentation/ios/startに示されているように ) 。アプリケーションでマップを取得します。
現在、Googleマップの下部にある画面にボタンを追加して、ユーザーが前の画面に戻るオプションを提供しようとしています。
UIButton は UIView のサブクラスであり、そのクラスのサブビューにすることでビューにボタンを表示できることを知っています。以前の iOS では、MKMapView によってデフォルトで Google マップを使用していました。地図上にボタンまたはテキスト ボックスが表示されるアプリのスクリーン ショットを示すインターネット上の書籍の例を見たことがあります。しかし、インターフェイス ビルダーでボタンをドラッグするだけでは、Google マップの SDK は役に立ちません。
これが私のコードです:
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <GoogleMaps/GoogleMaps.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *btn;
@end
ViewController.m
#import "ViewController.h"
#import <MapKit/MapKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()
@end
@implementation ViewController
{
GMSMapView *mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadView
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];
//Latitude and longitude of the current location of the device.
double lati = locationManager.location.coordinate.latitude;
double longi = locationManager.location.coordinate.longitude;
NSLog(@"Latitude = %f", lati);
NSLog(@"Longitude = %f", longi);
CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:lati longitude:longi];
// Create a GMSCameraPosition that tells the map to display the coordinate
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lati
longitude:longi
zoom:11.5];
mapView_ = [GMSMapView mapWithFrame:[[UIScreen mainScreen] bounds] camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(lati, longi);
marker.title = @"It's Me";
marker.snippet = @"My Location";
marker.map = mapView_;
[mapView_ addSubview:_btn];
[mapView_ bringSubviewToFront:_btn];
}
@end
最後の 2 行で、ボタンを mapview のサブビューにして前面に表示しようとしたことがわかります。しかし、これは役に立ちませんでした。何が欠けているのか、または他の機能を使用してこれを行う別の方法があるかどうかを教えてください。
私がここでやろうとしていることをよりよく理解できるように、私が作成したストーリーボードのスクリーンショットも確認してください。
ありがとう。