如何移动一个点在谷歌地图编程xcode



我创建了一个应用程序,并使用它的谷歌地图api。我想把动画移动一个点(例如我的位置)到顶部。那件事我不知道,请给我指点一下。

我想当点击移动按钮我的地图移动到顶部(100px)请告诉我怎么做?

这是我的代码:

@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
    // nokte mohem ine ke baadan ye logitude & latitude default ezafe kon chon shaiad tuie ye sharaiete tokhmi ke hamid esrar dare va ye kasi mariz bood dastresie GPS ro ghat kard
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitudes longitude:longitudes zoom:14];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero  camera:camera];
    mapView_.myLocationEnabled = YES;
    [mapView_ setMapType:kGMSTypeNormal];
    self.view = mapView_;
    [mapView_ addSubview:pinButton];
    [mapView_ addSubview:add];
}
- (IBAction)Move:(id)sender{
    //move marker place
}
- (IBAction)ShowMyLocation:(id)sender{
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(coor.latitude,coor.longitude);
    marker.title = @"I'm Here";
    marker.snippet = @"Rahnova Co.";
    marker.appearAnimation = kGMSMarkerAnimationPop;
    marker.map = mapView_;
}
- (void) GetMyLocation{
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    CLLocation *currentLocation = newLocation;
    if (currentLocation != nil) {
        longitudes = currentLocation.coordinate.longitude;
        latitudes = currentLocation.coordinate.latitude;
    }
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitudes longitude:longitudes zoom:14];
    [mapView_ animateToCameraPosition:camera];
}

这是在Google内部移动的一种方法,即设置Mapview的摄像头

- (IBAction)Move:(id)sender{
  //move marker place
  CLLocationCoordinate2D moveToCoordinate = CLLocationCoordinate2DMake(0, 0);
  //0, 0 are the Coordinates that you wan to,
  GMSCameraPosition *camera =
  [GMSCameraPosition cameraWithLatitude:moveToCoordinate.latitude
                            longitude:moveToCoordinate.longitude
                                 zoom:14];
  [mapView_ animateToCameraPosition:camera];
}

相关内容

  • 没有找到相关文章

最新更新