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
Related
I want to create a draggable marker but it doesn't work. What am I missing?
let marker = NMAMapMarker(geoCoordinates: coordinates, image: markerImage!)
marker.isDraggable = true
mapView.add(mapObject: maker)
mapView.respond(to: .markerDragBegan) { (drag, map, marker) -> Bool in
return true
Please take a reference from below sample code. Also share the error logs that you got while using above code snippet.
/**
* create a NMAMapMarker object, then add it to current active map view.
*/
- (void)addMapMarker {
//create NMAImage with local cafe.png
NMAImage* markerImage = [NMAImage imageWithUIImage:[UIImage imageNamed:#"cafe.png"]];
//create NMAMapMarker located with geo coordinate and icon image
NMAMapMarker* mapMarker = [NMAMapMarker mapMarkerWithGeoCoordinates:self.mapView.geoCenter icon:markerImage];
//make marker able to receive dragging gesture from map
mapMarker.draggable = YES;
//add NMAMapMarker to map view
[self.mapView addMapObject:mapMarker];
//add view and handlers for *MarkerDrag* events:
[self setupMapMarkerEventHandlersIfNeeded];
[_mapMarkers addObject:mapMarker];
}
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
I'm using the following code to see when markers enter the screen :
let visibleRegion = mapView.projection.visibleRegion()
let bounds = GMSCoordinateBounds(region: visibleRegion)
for i in stride(from: 0, to: markers.count, by: 1){
let marker = markers[i]
if bounds.contains(marker.position) {
print("Is present on screen")
print(marker.position)
} else {
// Marker not on the screen
}
}
This works and when I scroll the map on top of a marker I get the printout.
I've got 30k markers that I'm needing to potentially place onto the map. The markers show up at different zoom levels, and only need to be loaded once the user is able to see them.
The marker is a rounded image view, so as you an imagine loading 30 thousand pictures into a map is a huge task.
I have JSON that I am loading in the Lon/Lat/ImageURL.
Do I need to deinit markers as they leave the screen and init them as they come onto the screen? Are google map annotations reused like a tableview cell? Should I only create the marker once a location from my JSON is in the bounds of the map, or can I create them and only add them to the map once they're in the bounds? What sort of optimization tools should I use?
Thanks for any tips here
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
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
}