"Reached the Max Number of Texture Atlases, Can Not Allocate More" Using Google Maps

Google Map getting crashed after drawing around more than 1300 markers with custom color setting icon property

How about to use struct of image? Wo do not need to call GMSMarker.markerImage() thousands times.

struct MarkerImage {
static let green = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "GREEN"))
static let yellow = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "YELLOW"))
static let red = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "RED"))
}

func getIcon(color: String) -> Image {
switch(color) {
case "GREEN": return MarkerImage.green
case "YELLOW": return MarkerImage.yellow
default: return MarkerImage.red
}
}

marker.icon = getIcon(color)

If it works, we could create an enum of the color names, and extend that to return an image.

Optimising custom marker image performance with Google Maps SDK for iOS

Answering my own question after coming across the issue again.

The problem appears to be that I am allocating a separate UIImage instance to each marker. This means that when I am plotting markers on the GMSMapView instance, each marker has a separate UIImage. This is described briefly here: Customize the marker image - Google Maps SDK for iOS.

If you are creating several markers with the same image, use the same instance of UIImage for each of the markers. This helps improve the performance of your application when displaying many markers.

I was iterating through a list of objects to create each marker:

for (int i = 0; i < [array count]; i++) {
UIImage *image = [UIImage imageWithContentsOfFile:@"image.png"];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(10, 10);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.icon = image;
marker.map = mapView_;
}

So here, I was copying the image to each marker. That took up more resources than necessary. The solution for me:

UIImage *image = [UIImage imageWithContentsOfFile:@"image.png"];

for (int i = 0; i < [array count]; i++) {
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(10, 10);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.icon = image;
marker.map = mapView_;
}

Defining the UIImage instance outside of the for-loop meant that the image was referenced from each marker, not re-rendered for each marker. Memory usage was much lower after this.

GoogleMaps SDK for iOS - SWIFT 3: When hiding a marker and then adding the map view back, the cpu gets stuck at 100%

This is clustering approach I am using

//method to detect when user scrolls map
@objc(mapView:didChangeCameraPosition:) func mapView(_: GMSMapView, didChange _: GMSCameraPosition) {
self.counter = self.counter + 1
self.requestForMap(counter: self.counter)
}

//if user did nothing for 0.2 seconds request data from server
fileprivate func requestForMap(counter: Int) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { [weak self] in

guard let `self` = self else {
return
}

if counter == self.counter {
self.sessionManager.session.invalidateAndCancel()
self.requestData()
}
}
}

to get pins in area I do this on client

// get coordinates of visible area
extension GMSMapView {

func boundings() -> [String: Any] {
let screenBounds = UIScreen.main.bounds
let topPoint = CGPoint(x: 15, y: 60)
let bottomPoint = CGPoint(x: screenBounds.width - 15, y: screenBounds.height)
let shoudBeFull = self.camera.zoom > 15 //if user is zoomed in a lot request all data in area
let bouding = [
"top": [
"lat": self.projection.coordinate(for: topPoint).latitude,
"lon": self.projection.coordinate(for: topPoint).longitude,
],
"bottom": [
"lat": self.projection.coordinate(for: bottomPoint).latitude,
"lon": self.projection.coordinate(for: bottomPoint).longitude,
],
"full": shoudBeFull,
] as [String: Any]
return bouding
}
}

then this data as JSON is passed to the server and the server gets pins' data for objects, coordinates of which are inside this bounding. We are using node.js, not sure how it works there.

Then I have an array of currently displayed pins like var pins = [GMSMarker], after I get an array of objects from server I go through this array, remove those, which are not in new data and add those, which are new

Cannot add more than one marker in google map (flutter)

Most probably

_navigationList.last.userId.toString() == _navigationList.first.userId.toString()

how to show markers only in gmscircle region otherwise hide in ios

You can use following simple idea for it.

-(BOOL) checkMarker:(CLLocation*)locB

{
CLLocation *locA = [[CLLocation alloc]
initWithLatitude:24.590095
longitude:73.698256];

CLLocationDistance distance = [locA distanceFromLocation:locB];
NSLog(@"%f",distance);

if(distance <= RADIUS)
{
NSLog(@"You are in Circle ");
return true;
}
else
{
NSLog(@"You are not in circle");
return false;
}
}


Related Topics



Leave a reply



Submit