I want to fix the marker in the center of the map irrespective of the location coordinates. If the user moves the camera on map I want it to keep showing up in the center without any flickering in marker and new location on that marker shows, How can I do that? Please help out.
Try the below code
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 ;)
}