Objectiveec fixed marker in the center of google ios map

I want to fix the marker in the center of the map regardless of location coordinates. If the user moves the camera to the map, I want it to continue to appear in the center, without any flickering of the marker, and the new location on this marker shows how I can do this? Please, help.

+4
source share
3 answers

Try the code below

GMSCameraPosition *cameraPosition;

- (void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position {

        /* move draggable pin */
        if (fixedMarker) {

            // stick it on map and start dragging from there..
            if (lastCameraPosition == nil) lastCameraPosition = position;

            // Algebra :) substract coordinates with the difference of camera changes
            double lat = position.target.latitude - lastCameraPosition.target.latitude;
            double lng = position.target.longitude - lastCameraPosition.target.longitude;
            lastCameraPosition = position;
            CLLocationCoordinate2D newCoords = CLLocationCoordinate2DMake(fixedMarker.googleMarker.position.latitude+lat,
                                                                          fixedMarker.googleMarker.position.longitude+lng);
            [fixedMarker.googleMarker setPosition:newCoords];
            return;
        }

    }

    - (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position {

        cameraPosition = nil; // reset pin moving, no ice skating pins ;)

    }
+2
source

Try below C code

Do not forget to set the delegate

  mapView.delegate=self;

Create an ImageView and add it to the center of the map

UIImageView *pin =[[UIImageView alloc]init];
pin.frame=CGRectMake(0, 0, 20, 20  );  
pin.center = mapView.center;
pin.image = [UIImage imageNamed:@"location.png"];
[self.view addSubview:pin];
[self.view bringSubviewToFront:pin];

Google.

//When You Will Scroll Map Then This Method Will Be Called
     - (void)mapView:(GMSMapView *)MapView didChangeCameraPosition:(GMSCameraPosition *)position {

            // Get Latitude And Longitude Of Your Pin(ImageView)
              CLLocationCoordinate2D newCoords = CLLocationCoordinate2DMake( position.target.latitude , position.target.longitude);

              NSLog(@"Latitude-%f\Longitude-%f\n",newCoords.latitude, newCoords.longitude);


     [[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(newCoords.latitude, newCoords.longitude) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {

             //Get Place Details
             NSLog(@"%@",[[response results]objectAtIndex:0].lines);

    }];           
              return;
     }
+2

( ) GMSMapView GMSMapView.

And if you want to get the coordinates, you can use mapView.projection.coordinateForPoint

This will move the marker

Find the center point of a google map by the following code

let centerCord = yourMapView.camera.target 

let marker = GMSMarker(position: centerCord)
marker.title = "Hello World"
marker.map = mapView

Implement mapView: didChangeCameraPosition:

 func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
     // to remove all markers       
     mapView.clear()

    //create new marker with new center
    let centerCord = [yourMapView.camera target] 

    let marker = GMSMarker(position: centerCord)
    marker.title = "Hello World"
    marker.map = mapView


    }
+1
source

Source: https://habr.com/ru/post/1674054/


All Articles