Remove only polylines from GMSMapView without reference of them - ios

How to remove only the polylines from my GMSMapView in Swift.
I don't use map.clear() because I have like 100 markers and groundOverlays that I don't want to delete and I do not have references of them.

Keep a record of the Polyline Array and set the .map property to nil for each polyline you want to remove.
let poly = GSMPolyline()
poly.map = mapView to show
poly.map = nil to remove

Related

Move and/or Remove Markers in ArcGIS Graphics Layer

I'm using the ArcGIS 100.6 iOS SDK and am populating the map with markers on a Graphics Overlay Layer
whose locations are stored in a database common to all users of my application. Each marker is stored in a unique record and each record contains the Latitude & Longitude of the marker.
When the App is launched it reads the location of all markers in the database and adds each one to the Graphics Overlay as shown below:
let areaMarker = AGSPictureMarkerSymbol(image: UIImage(named: "CustomMarker")!)
let areaMarkerLocation = AGSPointMakeWGS84(y ?? 0.0, x ?? 0.0)
let markerIcon = AGSGraphic(geometry: areaMarkerLocation, symbol: areaMarker, attributes: >["marker": markerKey])
self.overlay.graphics.add(markerIcon)
As shown above, each marker is assigned an attribute "marker:markerKey" that is the unique database record number (key) where the marker location information is stored and serves as the marker ID.
Once the initial markers are added to the Overlay, the App "Listens" to the database for the following events:
A new marker is added
An existing marker is moved to a new location
An existing marker is deleted
When a marker is moved or deleted the database listener is notified and passed the record number (key) of the marker that was moved (or deleted). If the marker was moved, the record will then contain the new Latitude & Longitude information.
I have experimented with reading the graphics overlay and determined that it is a Collection contained in a NSMutable Array. I can read all attributes as follows:
let graphicsCollection = self.overlay.graphics.mutableArrayValue(forKey: "attributes")
print(graphicsCollection)
The result is:
(
{
marker = "-KlRW2_rba1zBrDPpxSl";
},
{
marker = "-Lu915xF3zQp4dIYnsP_";
}
)
I can do the same for "geometry" and get the array of AGSPoints:
let graphicsCollection = self.overlay.graphics.mutableArrayValue(forKey: "geometry")
print(graphicsCollection)
The result is:
(
"AGSPoint: (-117.826127, 44.781139), sr: 4326",
"AGSPoint: (-112.056906, 33.629829), sr: 4326"
)
I have been unable to determine how to get the "index" of the attribute array (e.g. marker "-KlRW2_rba1zBrDPpxSl" above should have an index of [0]) so I can then use that "index" to access the appropriate AGSPoint and update the Latitude & Longitude or remove the marker.
Thanks in advance for the help.
If you want to move the marker (i.e. an AGSGraphic) you'll want to get the AGSGraphic itself and modify the geometry property. I think that by jumping to the "geometry" in your mutableArrayValue() call you're kind of shooting yourself in the foot a bit.
I would tackle it this way:
let searchMarker = "-KlRW2_rba1zBrDPpxSl"
let newLocation = AGSPointMakeWGS84(40.7128, -74.0060) // NYC
if let graphic = (overlay.graphics as? [AGSGraphic])?.first(where: {
($0.attributes["marker"] as? String) == searchMarker
}) {
// Move the graphic
graphic.geometry = newLocation
// Or remove the graphic
overlay.graphics.remove(graphic)
}

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

How to hide google map markers swift

I want to hide the marker after the zoom level reach 17, someone suggested I use clear method, but the issue with it that I have different marker that will show after some event so clear is not going to work any idea how can I made this possible?
To remove a specific marker
myMarker.map = nil
as far as I know there are no definite references to hiding markers, but you can manipulate marker data displayed on the map #CMIIW
as an example
var markers: [GMSMarker] = []
var tempMarker: [GMSMarker] = []
if zoom == 17 {
// TODO: Create tempMarker filter from markers
} else {
// TODO: Create tempMarker filter from markers
}
// TODO:
// mapView.clear()
// Mapview show markers from tempMarker
iOS Swift Google Maps SDK showing markers at specific zoom level?
//To delete
marker.map = nil
//to hide
marker.opacity = 0.0

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
}

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