Tôi mới sử dụng Lập trình iOS và có rất ít kiến thức về COCOA Touch. Tôi đang cố thêm một nút trên màn hình ở phía dưới bản đồ Google để đưa ra tùy chọn cho người dùng quay lại màn hình trước đó. Tôi chỉ biết rằng UIButton
là một phân lớp của UIView
và chúng tôi có thể làm cho nút xuất hiện trên một chế độ xem bằng cách đặt làm chế độ xem phụ của lớp đó. Trước đây, iOS được sử dụng để sử dụng Google Maps theo mặc định trong MKMapView
và tôi đã xem các ví dụ trong sách trên Internet hiển thị ảnh chụp màn hình ứng dụng có nút hoặc hộp văn bản sẽ xuất hiện trên bản đồ. Nhưng bây giờ chỉ cần kéo nút trong trình tạo giao diện không giúp được gì.Thêm tiểu sử như UISlider hoặc UIButtom vào Google Maps trong iPhone
Đây là mã của tôi:
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
Xin vui lòng cho tôi k bây giờ làm thế nào nó có thể được thực hiện.
Cảm ơn.
bản đồ google và MKMapView không liên quan và có tính năng khác được đặt/làm theo cách tiếp cận khác –
nhưng .. chỉ làm cho thanh trượt làm hiển thị bản đồ. sẽ làm việc tốt với MKMapView –
Tôi biết nó sẽ làm việc tốt với MKMapView. Nhưng Theo như tôi biết MKMapView sẽ không cho tôi Google Maps. Nó sẽ cho tôi những bản đồ do Apple cung cấp. Đó là vấn đề thực sự của tôi. –