Gmsmarker Icon in the Top Left Corner of the View (Ios)

Swift GMSMarker icon in the top left corner of the view

I've figured out a fix so I'm putting it here in case someone else has this issue.

I changed from using mapView?.animate to GMSCameraPosition.camera and it seems to be working fine.

func centerMapOnLocation(location: CLLocation)
{
let target = CLLocationCoordinate2D(latitude: locationManager.location!.coordinate.latitude, longitude: locationManager.location!.coordinate.longitude)
mapView.camera = GMSCameraPosition.camera(withTarget: target, zoom: zoom)
}

GMSMarker icon from center (iOS)

You can change the start position of your marker icon with the property groundAnchor.

Google Maps SDK for iOS documentation:

The ground anchor specifies the point in the icon image that is
anchored to the marker's position on the Earth's surface. This point
is specified within the continuous space [0.0, 1.0] x [0.0, 1.0],
where (0,0) is the top-left corner of the image, and (1,1) is the
bottom-right corner.

Example:

The below example rotates the marker 90°. Setting the groundAnchor
property to 0.5,0.5 causes the marker to be rotated around its center,
instead of its base.

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
CLLocationDegrees degrees = 90;
GMSMarker *london = [GMSMarker markerWithPosition:position];
london.groundAnchor = CGPointMake(0.5, 0.5);
london.rotation = degrees;
london.map = mapView_;

GoogleMaps camera target in top left corner of map iOS since pod update

I found I was able to solve this problem by adding the map creation to ViewWillAppear as opposed to having it in the ViewDidLoad.

 override func viewWillAppear(_ animated: Bool) {
let ud = UserDefaults.standard
let startingX = ud.double(forKey: "startingX")
let startingY = ud.double(forKey: "startingY")

let camera = GMSCameraPosition.camera(withLatitude: startingX, longitude: startingY, zoom: 18.0)
googleMapView.camera = camera

self.googleMapView.mapType = .hybrid

self.googleMapView.settings.scrollGestures = true
self.googleMapView.settings.rotateGestures = true
self.googleMapView.settings.consumesGesturesInView = true
}

Why is there a plus icon at the top right corner of my view?

It is managed by DropProposal drop operation and by default (if you do not provide explicit drop delegate) is .copy as documented, which adds '+' sign. By this you inform user that something will be duplicated.

/// Tells the delegate that a validated drop moved inside the modified view.
///
/// Use this method to return a drop proposal containing the operation the
/// delegate intends to perform at the drop ``DropInfo/location``. The
/// default implementation of this method returns `nil`, which tells the
/// drop to use the last valid returned value or else
/// ``DropOperation/copy``.
public func dropUpdated(info: DropInfo) -> DropProposal?

if you want to manage it explicitly then provide DropDelegate with implemented drop update as in below demo

func dropUpdated(info: DropInfo) -> DropProposal?
// By this you inform user that something will be just relocated
return DropProposal(operation: .move)
}

Change Google Map Marker Inset iOS

For the record, I was able to pull it off, using the GMSMarker's groundAnchor.

GroundAnchor:

The ground anchor specifies the point in the icon image that is
anchored to the marker's position * on the Earth's surface. This
point is specified within the continuous space [0.0, 1.0] x [0.0, *
1.0], where (0,0) is the top-left corner of the image, and (1,1) is the bottom-right corner. * * If the image has non-zero
alignmentRectInsets, the top-left and bottom-right mentioned above *
refer to the inset section of the image.

Although if someone could explain this in much simpler way, that would be helpful. What I did was I put two textFields and a button at the center of my map and put random values (e.g. 0.1, 0.5, etc...) to set the specific marker's groundAnchor, then voila, I got the appropriate values.



Related Topics



Leave a reply



Submit