Use of unresolved identifier 'MapTasks' - ios

I wanna add marker in my app in google maps
I have this error
Use of unresolved identifier 'MapTasks'
var mapView: GMSMapView?
var locationManager = CLLocationManager()
var locationMarker: GMSMarker!
var mapTasks = MapTasks() ---> error
all my problem is that I can't add optional marker when user touch in google maps.

In adding marker when user touch the map, use didTapAtCoordinate this was called after a tap gesture at a particular coordinate, but only if a marker was not tapped. Or, didLongPressAtCoordinate when long press gesture at a particular coordinate.
To add a marker, you need to create a GMSMarker object that includes a position and title and set its map.
The following example demonstrates how to add a marker to an existing GMSMapView object. The marker is created at coordinates 10,10, and displays the string "Hello world" in an info window when clicked.
let position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.title = "Hello World"
marker.map = mapView
Here's a related SO ticket, discuss regarding touch event: Google Maps iOS SDK Touch Events

Related

How to remove a marker from the previous point from GoogleMap and add another new marker into that position

I am trying to remove a marker from the previous position and add a new marker into that position again in google map. I don't want to clear the whole map.
Please help.
To remove the marker set map property to nil.
marker.map = nil
let newMarker = GMSMarker(position: oldMarker.position)
newMarker.map = mapView
oldMarker.map = nil

Get all GMSMarker from mapview and remove all marker without using mapview.clear()

I have drawn path with marker in google map. So the path is static but marker needs to change their positions. How can I remove all markers without using mapview.clear(), because it will clear my path also from the map.
Any solution?
I guess you will have to keep all markers in an array(eg. allMarkers). Then,
for marker in allMarkers {
marker.map = nil
}

GMSMarker icon in the top left corner of the view (iOS)

I am trying to create a UITableViewCell containing a GMSMapView with a GMSMarker at the center of the current Position.
The problem is that the marker always appears at the top left corner of the current position and I don't know how to solve the problem.
I tried to follow these steps: Implementing a Google Map with UItableviewCell
here is my code from cellForRowAt:
let locationCell = tableView.dequeueReusableCell(withIdentifier: "activityLocationCell") as! ActivityLocationCell
let latitude = CLLocationDegrees(activity.coordinates![0])
let longitude = CLLocationDegrees(activity.coordinates![1])
let position = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
locationCell.googleMapView.camera = GMSCameraPosition.camera(withTarget: position, zoom: 15)
let marker = GMSMarker(position: position)
marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
marker.map = locationCell.googleMapView
return locationCell
Here is a screenshot of my problem:
marker is at the top left corner of the map
I had a pretty similar issue. I resolved it by changing the moment I configure the map in the view lifecycle.
In my case, I was using a child view controller. I was configuring the map before viewWillAppear was called which caused the map to not center properly (the marker was on the top left corner). I moved my call to after the viewWillAppear and it fixed it. A good place would be viewDidAppear.
If you are using a cell, you will probably need to investigate with the view lifecycle instead of the controller lifecycle.
This is not written anywhere on the Google documentation.
you have to draw map in
func viewDidLayoutSubviews()
Try creating Marker when map is ready completely. for eg: use the delegate.
var ifMapReady: Bool = false
...
...
func mapViewSnapshotReady(_ mapView: GMSMapView) {
ifMapReady = true
}
//Call this method from where ever you want to load map
func updateMap() {
if ifMapReady {
//Load Map
}
}
This delegate will be called multiple times(eg: map is swiped or moved etc) whenever the Map tiles are ready. So we can use a boolean value for understanding that map loaded successfully. Based on that value we can load the Map properly when initiating.
I want to add one more thing. #Gabriel Cartier's answer worked for me with one additional change in my code.
[self->mapView_ animateToCameraPosition:camera];
And I replaced with
[self->mapView_ setCamera:camera];

Custom user location dot in Google maps for iOS (GMSMapview)

Is there an official way to set a custom user location dot in Google maps for iOS (GMSMapView)?
Is there a known way to "hack" it? Like iterating through all subviews and layers and fish the blue dot?
Even if you can't customise its appearance, can you control its z order index? When you have many markers, the little blue dot becomes hidden, and sometimes you want it to be visible at all times.
Thanks
You can try to find the image on:
GoogleMaps.framework > Resources > GoogleMaps.bundle
OR
GoogleMaps.framework > Resources > GoogleMaps.bundle > GMSCoreResources.bundle
I did a quick search on those and the only associated file I found with that blue dot is GMSSprites-0-1x.
Please read the google maps terms and conditions because this might not be legal.
You can set the maps myLocationEnabled to NO. That will hide the default location dot. Then use an instance of CLLocationManager to give you your position. Inside CLLocationManager didUpdateLocations method you can set a custom GMSMarker. Set its icon property to whatever you want your dot to look like using [UIImage imageNamed:]. This will allow you to achieve the desired effect.
Swift 4
Disable the default Google Map current location marker (it's disabled by default):
mapView.isMyLocationEnabled = false
Create a marker as an instance property of the view controller (because a delegate will need access to this):
let currentLocationMarker = GMSMarker()
The GMSMarker initializer allows for a UIImage or a UIView as a custom graphic, not a UIImageView unfortunately. If you want more control over the graphic, use a UIView. In your loadView or viewDidLoad (wherever you configured the map), configure the marker and add it to the map:
// configure custom view
let currentLocationMarkerView = UIView()
currentLocationMarkerView.frame.size = CGSize(width: 40, height: 40)
currentLocationMarkerView.layer.cornerRadius = 40 / 4
currentLocationMarkerView.clipsToBounds = true
let currentLocationMarkerImageView = UIImageView(frame: currentLocationMarkerView.bounds)
currentLocationMarkerImageView.contentMode = .scaleAspectFill
currentLocationMarkerImageView.image = UIImage(named: "masterAvatar")
currentLocationMarkerView.addSubview(currentLocationMarkerImageView)
// add custom view to marker
currentLocationMarker.iconView = currentLocationMarkerView
// add marker to map
currentLocationMarker.map = mapView
All that remains is giving the marker a coordinate (initially and every time the user's location changes), which you do through the CLLocationManagerDelegate delegate.
extension MapViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let lastLocation = locations.last!
// update current location marker
currentLocationMarker.position = CLLocationCoordinate2D(latitude: lastLocation.coordinate.latitude, longitude: lastLocation.coordinate.longitude)
}
}
The first few locations that the location manager produces may not be very accurate (although sometimes it is), so expect your custom marker to jump around a bit at first. You can wait until the location manager has gathered a few coordinates before applying it to your custom marker by waiting until locations.count > someNumber but I don't find this approach very attractive.

MKAnnotation just shown after move camera (swift)

I am trying to use the MapKit-Framework in iOS. I have a map, where I draw a polyline.
Now I want to add some simple annotations. I add them to the map, but they are not shown directly. I have to move the camera. After I move the camera or use the zoom, the annotations are visible.
What I have to call to refresh the map to show the annotations directly?
var zugEndeAnnotation : MKPointAnnotation = MKPointAnnotation();
zugEndeAnnotation.coordinate = CLLocationCoordinate2D(latitude: zugEnde.coordinate.latitude , longitude: zugEnde.coordinate.longitude);
self.map.addAnnotation(zugEndeAnnotation);
best regards

Resources