Optimization for many markers on Google Map ios sdk? - ios

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

Related

Adding text to screen space with reailtykit, swift and swiftui

How to add text to screen space in RealityKit/SwiftUI?
All the tutorials online are about adding text to screen space with UIKit/Scene Kit, but it never uses SwiftUI/RealityKit. Even Apple's uses UIKit for most of their examples!
Apple's example of screen space
It's not a straightforward conversion from Apple's explain into SwiftUI/RealityKit. Apple would get the 2d screen point, but then update the UIText's view frame with that 2d screen point.
To put the annotation in the right place on the screen, ask the ARView
to convert its entity’s world location to a 2D screen point.
guard let projectedPoint = arView.project(note.position) else { return }
All I have right now is a tap handler that would raycast to the tap location. From that I have world coordinates, which I use for my anchor position. I created a mesh of text, but when adding to the anchor, it exists in world space and isn't aligned properly
let raycastResults = self.raycast(from: tapLocation, allowing: .estimatedPlane, alignment: .any)
guard let raycastFirstResult: ARRaycastResult = raycastRes.first else { return }
let position = raycastFirstResult.worldTransform
let mesh = MeshResource.generateText("Test")
Has anyone added text to world space using SwiftUI/RealityKit before?

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

How to animate Marker from coordinate A to B in Google Maps iOS (Swift) in a particular duration

I want to animate Marker on GoogleMaps for iOS
between 2 points in at a particular speed or duration
like point A and B are two points and I want to move marker from A to B
then how to do it if I want to do in a particular time frame like suppose 3 seconds then it automatically takes 3 seconds to move from Coordinate A to B.
I want to make effect somewhat like Uber have when cars are moving from one point to another.
You can use DispatchQueue.main.asyncAfter like,
func showFirstMarker()
{
// Fetch the coordinates of first location and plot as marker.
// Call a function after 3 seconds, to show the second marker.
DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: {self.showSecondMarker()})
}
func showSecondMarker()
{
// Erase all markers in maps.
// Fetch the second coordinate and plot as marker.
}

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.

MKMapView Doesn't Show Whole World At Once

I'm working on an application that tracks movement in Swift, for traveling from point A: locationOne, to point B: locationTwo. The MapView should display both points on the map, centered in between them.
I implemented a function to determine the center location as per this link, though I had to modify it to function in Swift. The function is called findCenterPoint.
Then, I set the mapView's region to an MKCoordinateRegion. This region is created like so: let region = MKCoordinateRegionMakeWithDistance(center, 2*distanceOne, 2*distanceTwo), and then the mapView's region is set like this: mapView.setRegion(region, animated: false)
I multiply the distance by 2 so that we have a margin on the sides of the two locations (the annotation for locationOne, and locationTwo: the user location)
Here's the problem: If the two points are very far away, i.e. New York and somewhere in Australia (let's just say general Australia) the app can't display both points, because they don't fit on the mapView. So instead, only one pin is visible, because the other one is off the screen.
Screenshots of problem
I need both of those points to show up without scrolling around the map.
I also have a degreesToRadians function which is used in the code below.
TL;DR: My app's mapView isn't big enough to fit and display two far away points on the map, and it is already zoomed out to the max.
Here's the actual code:
var center = findCenterPoint(firstLocation.coordinate, locTwo: placemark.coordinate)
let earthRadius: Double = 6371000
distance = degreesToRadians(placemark.coordinate.latitude - firstLocation.coordinate.latitude)
lonDistance = degreesToRadians(placemark.coordinate.longitude - firstLocation.coordinate.longitude)
let region = MKCoordinateRegionMakeWithDistance(center, earthRadius*distance, earthRadius*lonDistance)
mapView.setRegion(region, animated: false)

Resources