How to move marker on the Google Map like Ola app

前端 未结 3 1059
日久生厌
日久生厌 2021-01-03 17:15

I am working on app the like Ola cabs. When the user drags map the a view transparent view appears with marker moving and when the user stops dragging the we have to centre

3条回答
  •  梦谈多话
    2021-01-03 18:01

    @interface ViewController ()  {
        GMSMarker *marker2;
    }
    

    In viewDidLoad

    marker2 = [[GMSMarker alloc] init];
    
    // Create a GMSCameraPosition that tells the map to display the
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
                                                            longitude:longitude
                                                                 zoom:18];
    // Create GMSMapView
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    
    // Available map types: kGMSTypeNormal, kGMSTypeSatellite, kGMSTypeHybrid,
    // kGMSTypeTerrain, kGMSTypeNone
    
    // Set the mapType to Satellite
    mapView.mapType = kGMSTypeSatellite;
    
    
    mapView.myLocationEnabled = YES;
    self.view = mapView;
    
    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(latitude, longitude);
    marker.map = mapView;
    
    mapView.delegate = self;
    

    After that call delegate functions

    - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
    //    NSLog(@"willMove");
    }
    
    - (void) mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {
    //    NSLog(@"didChangeCameraPosition");
    
    // Creates a marker in the center of the map.
    
    //    NSLog(@"%@", position);
          marker2.position = CLLocationCoordinate2DMake(mapView.camera.target.latitude, mapView.camera.target.longitude);
          marker2.map = mapView;
    //    marker2.draggable = YES;
          marker2.icon = [GMSMarker markerImageWithColor:[UIColor blueColor]];
    
    
    }
    

提交回复
热议问题