我创建了一个 Mapkit 应用程序,在其中显示我的位置并每次更新此位置并将此位置设置在视图中心。我更新我的位置并使用布尔变量设置在中心。我想在地图上检测滚动或缩放触摸手指,当我这样做时,我的布尔变量发生了变化,并且没有将我的位置设置在中心,但我不知道如何处理 Mapkit 上的触摸事件。
请指导我,并告诉我如何在触摸和滚动地图时更改变量。谢谢。这是我的代码:
@implementation ViewController
{
CLLocationManager *locationManager;
double latitudes;
double longitudes;
BOOL updateLocation;
}
@synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
updateLocation = YES;
mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
mapView.mapType = MKMapTypeStandard;
mapView.zoomEnabled = YES;
mapView.scrollEnabled = YES;
mapView.showsUserLocation = YES;
[mapView.userLocation setTitle:@"I'm Here"];
[self.view addSubview:mapView];
mapView.delegate = self;
[self GetMyLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc] …
Run Code Online (Sandbox Code Playgroud) 我有一张地图,我可以用代码添加pin(注释).我想在运行我的应用程序时,在我的应用程序中添加注释时自动选择此注释,当单击地图而不是注释我的注释取消选择.我可以处理选择并取消选择我的注释,但肯定必须单击注释,直到选择并单击地图(另一个地方而不是注释),直到我的注释取消选择.
我不想要这个.我想在运行我的应用时自动选择我的注释,只需要在地图上点击另一个地方,直到我的注释取消选择.
请指导我.这是我处理select/deselect注释的代码:
static NSString* const ANNOTATION_SELECTED_DESELECTED = @"mapAnnotationSelectedOrDeselected";
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSLog(@"2");
NSString *action = (__bridge NSString *)context;
if ([action isEqualToString:ANNOTATION_SELECTED_DESELECTED]) {
BOOL annotationSelected = [[change valueForKey:@"new"] boolValue];
if (annotationSelected) {
NSLog(@"Annotation was selected, do whatever required");
}else {
NSLog(@"Annotation was deselected, do what you must");
}
}
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
if ([mapViews.annotations count] > 1) {
for (MKAnnotationView *anAnnotationView in views) {
[anAnnotationView addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:(__bridge void …
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用谷歌地图 api。我的应用程序中有两个按钮。第一个按钮在我的地图中添加了一个标记(图钉)。现在我想要第二个按钮将添加的图钉水平移动到页面的中心,并使其移动到离页面顶部 25% 的位置。我希望相机(用户正在查看的区域)也移动它。这是我的代码:
@implementation ViewController
{
double latitudes;
double longitudes;
CLLocationManager *locationManager;
GMSMapView *mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[self GetMyLocation];
UIButton *pinButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
pinButton.frame = CGRectMake(self.view.frame.size.width-80,self.view.frame.size.height-80, 60, 60);
[pinButton setTitle:@"Self" forState:UIControlStateNormal];
[pinButton setBackgroundColor:[UIColor whiteColor]];
[pinButton addTarget:self action:@selector(ShowMyLocation:) forControlEvents:UIControlEventTouchUpInside];
UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect];
add.frame = CGRectMake(20,self.view.frame.size.height-80, 60, 60);
[add setTitle:@"add" forState:UIControlStateNormal];
[add setBackgroundColor:[UIColor whiteColor]];
[add addTarget:self action:@selector(Move:) forControlEvents:UIControlEventTouchUpInside];
// Create a GMSCameraPosition that tells the map to display the
// …
Run Code Online (Sandbox Code Playgroud) ios ×3
objective-c ×3
mapkit ×2
annotations ×1
google-maps ×1
mkannotation ×1
touch ×1
uitouch ×1