当我在iOS的Google Map中点击地图时如何移动标记位置

时间:2019-07-17 13:39:11

标签: objective-c google-maps

最初,我在带有标记的地图上显示当前位置,当我点击地图上的蚂蚁位置时,我也需要更改标记的位置,  我在Google地图委托didTapAtCoordinate中尝试了它正在移动,但有时会正确移动,但有时又在移动,但是当前位置标记仍在同一地方,但是新标记在我点击地图的位置移动了[我附上我的代码屏幕快照以供参考] [1]谢谢提前!!

 - (void)viewDidLoad {
                [super viewDidLoad];

                _showMapView.delegate = self;
                marker = [[GMSMarker alloc] init];
                [self setForCurrentLocation];

                // Do any additional setup after loading the view from its nib.
            }
            #pragma mark - CLLocationManager delegate methods
            - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
            {
                NSLog(@"didUpdateLocations");
                CLLocation *newLocation; = [locations objectAtIndex:0];

                [locationManager stopUpdatingLocation];
                marker.position = newLocation.coordinate;
                marker.draggable = YES;
                marker.map = _showMapView;

                //    CLLocationCoordinate2D gpsTarget =
                //    CLLocationCoordinate2DMake( newLocation.coordinate.latitude,  newLocation.coordinate.longitude);
                _showMapView.camera = [GMSCameraPosition cameraWithTarget:newLocation.coordinate zoom:10];

            }
            - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
            {
                marker.position = coordinate;
            }
            #pragma mark - CLLocationManager delegate methods
            - (void)setForCurrentLocation
            {

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

                    if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
                        [locationManager requestWhenInUseAuthorization];
                    }

            }

0 个答案:

没有答案