I use google maps for my iOS app which primarily displays custom tiles.
I subclass the GMSSyncTileLayer and request the tile using URLSession.shared when I get the data back I pass it to the receiver like this:
let image = UIImage(data: D) ?? kGMSTileLayerNoTile
receiver.receiveTileWith(x: x, y: y, zoom: zoom, image: image)
This is correct according to the Google maps documentation and it successfully renders my tiles:
However, the instant the user pinches to zoom in the tiles are removed from the map and the custom tiles don't show up until the next level of tiles loads.
This behavior is different from MKMapKit and MapBox. They both scale custom tiles before the next level loads. Google maps does this for it's own base tiles. Any idea how to get the same behavior for custom tiles on Google maps iOS SDK?
Related
We are attempting to overlay MapBox vector tiles on a MapKit map, so far to no avail. The MKTileOverlay obviously doesn't support MVTs, so what MapKit function would allow us to overlay these tiles (including features, zoom levels, etc.) to our existing Apple Map?
Using raster tiles is not an option for our use case. The tiles must be vector tiles.
func addMap() {
let url = "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/1/0/0.mvt?access_token=YOUR_MAPBOX_ACCESS_TOKEN"
let tileOverlay = MKTileOverlay(urlTemplate: url)
mapView.addOverlay(tileOverlay)
}
From the Apple MapKit docs for MKTileOverlay, raster or bitmap images are required.
An overlay that covers an area of the map with tiles of bitmap images.
Since MapKit for iOS expects rasters, it is possible to make use of the Mapbox Raster Tiles API to serve up raster versions of your Mapbox tiles.
Your Swift URL would look like this:
let url = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/256/{z}/{x}/{y}#2x?access_token=YOUR_MAPBOX_ACCESS_TOKEN"
You can see an example of what the Mapbox Raster Tile API serves (this is noted in the Mapbox Docs).
curl https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/256/9/89/206#2x?access_token=YOUR_MAPBOX_ACCESS_TOKEN
I'm using Google Maps for iOS and I need to create a snapshot of a map. I know how to do that.
What I can't do is do it behind the scenes. I can't create a map that the user doesn't see, set up the bounds and markers, and then take a picture of it. The picture ends up blank.
The code (Swift) I am using is essentially
var mapView = GMSMapView(frame: CGRect(x: 0, y: 0, width: 300, height: 300));
I point the map then wait a while for the map tiles to load then
UIGraphicsBeginImageContext(mapView.frame.size);
mapView.layer.renderInContext(UIGraphicsGetCurrentContext());
var screenShotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
But I just get a gray box with a Google logo at the bottom left.
The following answer to a different question says that what I want is not possible with Google Maps for iOS.
https://stackoverflow.com/a/26279120/1672356
It suggests Google Maps' Static Maps web service as an alternative but I was using markers with custom icons and static maps requires you make those available publicly via some URL and I can't do that easily.
In the end I hacked it. I popup a big gray screen with a "Please Wait" message and behind it I have a Google Maps that I manipulate and take a screenshot of and then remove both map and gray screen and continue.
Ugh.
And I don't even know when the map is done loading, so I took a guess that 5 seconds will usually be enough time.
Sigh.
I'd like to draw a grid into my map, that represents the size of a tile at a certain zoom level. So for example I'd like to have a grid on my mapview that shows the outline of a zoom level 10 tile. So the outline of where this tile would be. No matter if the mapview itself is at zoom level 5 or 15, it should display the outline of where that tile would be placed.
The problem I have is how to calculate the proper rect that represents each visible "tile".
Any help is sooo much appreciated!!!
Or maybe the answer to following question would help:
How can I convert a MKMapRect to a MKTileOverlayPath?
I find that MapKit is way too limited when you want to start doing more and more with maps.
I would reccomend using Google Maps SDK for iOS: https://developers.google.com/maps/documentation/ios/start
and then using GMSTileLayer for the tiles:
https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_tile_layer
In the long run, replacing MapKit with Google maps gives you far more features and options and has better geolocation and reverse geolocation than Apple
You can also look at Mapbox. Between using TileMill to create a grid layer by setting the Map background to a pattern image, you could then only export zoom level 10 and either host it on Mapbox or export it to MBTiles format (SQLite-based). Then one of the Mapbox mobile toolkits could serve the tiles out as an overlay on your map.
We are looking for a drawing / mapping SDK for iOS with the following requirements:
Draw multiple polygons on a single view. polygon coordinates are based on earth lat/long
Do not show other map layers from satellite / street view / whatever - just the polygon data
Allow adding layers / text/ bubbles / etc.
Allow zoom in-out
Allow clicking on regions.
Calculate bounding rect automatically, and do not allow the user to scroll out of this area.
Is there an SDK that supports these requirements?
Thanks.
Check out the Mapbox iOS SDK. It's open source, allows you to hide the basemap (or create a custom basemap to whatever appearance you desire), constrain the panning and zooming, add vector polygons atop the baselayer(s), add text and labels, control interactivity, and more.
I need create an app for iOS using the GPS and MapKit. The idea is create my own map of my house for example and add it to the UIView or MKMapView and see the current position into the map.
see the image
You can use custom overlay on the map. Here is nice example of image overlay on the mapView.
Apple has provided sample code to do this with map tiles. Using the MapKnitter website you can geoposition your floor plan and export it in a format that Apple's code will accept.