MKAnnotation just shown after move camera (swift) - ios

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

Related

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
}

How to move annotation with animation in mapbox map?

I am using mapbox map in my iOS app. I added annotation in mapbox map by using this class MGLPointAnnotation.
Now the problem is i am unable to change its location. This is how i changing annotation location. But it is not moving. I need to remove first old one and again need to add new annotation but i don't want to do this.Please let me know how can i do this.
car.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lng)
I want the movement of annotation when location changed of annotation with smooth animation.
Also when there is a change in location i'm changing center of my mapbox map with camera. Let me know i am doing right or not.
// Optionally set a starting point.
bMbMapView.setCenter(cord, zoomLevel: 7, direction: bearing, animated: true)
bMbMapView.setDirection(bearing, animated: true)
// Create a camera that rotates around the same center point, rotating 180°.
// `fromDistance:` is meters above mean sea level that an eye would have to be in order to see what the map view is showing.
let camera = MGLMapCamera(lookingAtCenter: cord, fromDistance: 1000, pitch: 7, heading: 90)
// Animate the camera movement over 5 seconds.
bMbMapView.setCamera(camera, withDuration: 1, animationTimingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
A MGLAnnotationView is a UIView, so you should be able to animate changes with Core Animation: https://github.com/mapbox/mapbox-gl-native/issues/8378#issuecomment-287910768
Another option is to use a style source and layer, then update the source using a timer. This would likely be less smooth than using an animated annotation view.

Here Maps iOS SDK Map Markers not visible on the map

I have created NMAMapView object using storyboard and I am using the reference of that NMAMapView object in view controller code and added markers to it. In this case, the markers are visible on the screen
To set the zoom automatically I created NMABoundingBox, added markers to it and then set the bounding box to NMAMapView using setBoundingBox::withAnimation method.
But if I create the NMAPMapView object dynamically, set the view controller view frame to the NMAMapView and add it as a subview to view controller view and then added the markers to the view, then the markers are visible out of the map. I have to do a manual zoom out on the map to see the markers.
I have also tried using setBoundingBox::insideRect::withAnimation method of NMAMapView for the above dynamically created map scenario to set the zoom automatically. But the maps is being pointed to some random portion of the world with some inappropriate zoom.
Need resolution for this issue. Thanks
In my case, I see a marker on the map only if some image is set as an icon of NMAMapMarker. Looks like there's no default marker available.
let coordinates: NMAGeoCoordinates = ...
let image: UIImage = ...
let marker = NMAMapMarker(geoCoordinates: coordinates, image: image)
or
let coordinates: NMAGeoCoordinates = ...
let marker = NMAMapMarker(geoCoordinates: coordinates)
let image: UIImage = ...
marker.icon = NMAImage(uiImage: image)
Hopefully, it helps.

Use of unresolved identifier 'MapTasks'

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

Tilt map in Mapkit programmatically using Swift

I'd like to tilt the map at startup. (Same as the user does when scrolling up or down with 2 fingers)
Is this possible using Swift?
MKMapView Class Reference : http://goo.gl/djHXPn
Look at the camera property :
A camera object defines a point above the map’s surface from which to view the map. Applying a camera to a map has the effect of giving the map a 3D-like appearance. You can use a camera to rotate the map so that it is oriented to match the user’s heading or to apply a pitch angle to tilt the plane of the map.
Assigning a new camera to this property updates the map immediately and without animating the change. If you want to animate changes in camera position, use the setCamera:animated: method instead.
You must not set this property to nil. To restore the map to a flat appearance, apply a camera with a pitch angle of 0, which yields a camera looking straight down onto the map surface.
Try to create and set a camera (animated or not).
Edit :
I tried myself. Here is an example of how to use it :
let userCoordinate = CLLocationCoordinate2D(latitude: 58.592725, longitude: 16.185962)
let eyeCoordinate = CLLocationCoordinate2D(latitude: 58.571647, longitude: 16.234660)
let mapCamera = MKMapCamera(lookingAtCenterCoordinate: userCoordinate, fromEyeCoordinate: eyeCoordinate, eyeAltitude: 400.0)
let annotation = MKPointAnnotation()
annotation.setCoordinate(userCoordinate)
mapView.addAnnotation(annotation)
mapView.setCamera(mapCamera, animated: true)
You'll have to find your right eyeCoordinate depending on your location and tilt effect you want to have.
Swift 4
This is an easier way: you can set distance, pitch and heading:
let mapCamera = MKMapCamera(lookingAtCenter: userCoordinate, fromDistance: 10000, pitch: 65, heading: 0)
map.setCamera(mapCamera, animated: true)

Resources