Draw a grid onto an MKMapView - ios

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.

Related

Mapkit - Overzoomed custom tiles not rendering when Polygons are present

I'm providing an MKMapView with an MKTileOverlay that replaces the map content. The backing tile provider only goes up to zoom level 15. If the user zooms in beyond zoom level 15 it upscales the level 15 tiles on the map instead of going blank.
However, if there is an MKPolygon or MKPolyline present in the map sector, it will only display the shape. It will no longer render the backing tile under it. This only happens when you overzoom.
I've seen some discussiong about overzooming in MapKit but they all seem to be related to versions prior to iOS 7 when a large amount of the Maps appear to have been changed.
Does anyone have experience with this?
I realized that I was completely misinterpreting the functionality that MapKit provides for Map Tiles.
When I zoomed in and saw that my Tiles were rendering I assumed it was an overzoom feature. When the areas that had Polygons were not rendering the Map Tiles as these zoom levels I thought the Polygon Renderer was somehow shutting off the tile Renderer. As it turns out, because the only active renderer at that zoomed in level was the Polygon renderer that was the only part of the canvas being redrawn, so the rest of the canvas was just still showing what it already had on there.
In laymans' terms:
The Map Tile Renderer tells the map "I can draw this large area at zoom levels 0-5." The Polygon Renderer tells the map "I can draw this small area at all zoom levels."
When I'm at zoom level 5 both the Map Tile Renderer and the Polygon Renderer kick off and draw the regions they can handle. When I move into zoom level 6 only the Polygon Renderer kicks off. The map says "I have a renderer that can draw in this region so I'm going to redraw it with that information." Because the Map Tile Renderer doesn't provide tiles for zoom level 6 it won't kick off. The rest of the map still has tiles because there is no renderer that can draw for it, so the map just keeps what it already has on the canvas.
tl;dr: I mistook MapKit not making superfluous draw calls as an overzooming feature.

mbtiles: Is it possible to draw some lines on offline mbtiles map

I have an .mbtiles file and I am using it for offline map (iOS MapBox SDK). But my .mbtiles doesn't have enough data (just simple green rectangle). I want to draw some lines(roads) between points (I download it from my rest API). I found the solution to use RMShape, but I want to use already drawn map. I create my .mbtiles from osm and TileMill. Help me out please.
WhirlyGlobe-Maply SDK can help you achieve this.
It has a mapview and a globe view which you implement on your viewcontroller.
Then you create a layer using your mbtile file as shown below:
let tileSource = MaplyMBTileSource(mbTiles: "your-mbtile-filename")
You add this layer on the globe or map to display the tiles.
And using SDK's function like addShapes(), you can add, circles, vectors, labels, text and icons on the map/globe.
I tried adding lat and long lines programatically. Also tried adding some labels and spheres.
This is how it looks ->
WhirlyGlobe-Maply using mbtile and drawing on top of it

Maps on iOS: Drawing layers without showing the base 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.

Drawing a circle on MapView with specifiec radius on Monondroid

I'm trying to draw a circle with specific radius in km (for example 2km) on a MapView at specific lat/lng. I've found some samples:
Creating Custom Overlay on the map
Draw A Circle On Android MapView
Draw circle of certain radius on map view in android
I think first and second of above are useful but these are in Java and I need code for Mono for Android (Monodevelop).
I can't find Projection class in monodroid.
And can't use com.google.android.maps.Projection.
Can somebody help me how to use these codes in monodroid?
com.google.android.maps.Projection is an interface, so it is made available in Mono for Android as Android.GoogleMaps.IProjection to keep with normal C# conventions.
Similarly, where you'd use mapView.getProjection() in Java, in C# it is made available via the Projection property on MapView.
Xamarin has some tutorials on their site that go over how to use these to create custom overlays, so I'd suggest checking them out.

How can I implement the custom drawing search tool used in the Realtor iPad app?

The Realtor iPad app has done a very good job of implementing a custom drawing tool on top of mapkit that they use to query an area for homes. I am familiar with mapkit and its associated classes but I am unaware of how I could do some custom drawing with my finger and have it translate to a geospatial query. How to do it?
I'm not sure how far along you've made it with this, but your basic algorithm should look like this:
Draw a polygon overtop your map, then translate the coordinates of that polygon to "map" coordinates. In order to do that you would probably need to listen for gestures on a view other than the MKMapKit instance. With my limited knowledge of the MapKit's touch event handling you might have to overlay a different transparent view on the map when you want to draw, so touch events won't go through to the MapKit (if that makes any sense). You use your finger to pinch, zoom, pan and you won't want that functionality if you're trying to draw. In that view, you'll draw the shape tracing the user's finger, then translate the points drawn into map points.
The docs indicate that you can translate screen points to map points using the convertPoint:toCoordinateFromView: method on MKMapView.
Check this link for information on that: Trouble converting MapKit user coordinates to screen coordinates
This post provides a link that might help you with drawing the polygon:
To draw polygon on google map with MapKit framework
After you've drawn your polygon you'll want to "spatially" query your data. You could do that in several ways. Locally on the device or through a web service are two options. If your data is local to the device you'll have to do the cartographic math on your device. You'll also need to ensure that your point data (the X,Y's) are in the same projection and coordinate space as your polygon's information. Polygon intersection math is relatively straight forward to do, when your projections and coordinate systems line up.
Here's a link that can help you with the math.
https://math.stackexchange.com/questions/237/how-do-you-determine-if-a-point-sits-inside-a-polygon
Alternatively you could set up some web service that takes your polygon data and performs the same cartographic math on a server and returns the results to the device. Either way the same math needs to be performed. You'll take that polygon data and determine which records in your data intersect with that polygon.
This is pretty high-level, I know, but it should be all you need to do.
Another consideration is if your data is spatially enabled with spatialite compiled for SQLite on your device or SQL Server Spatial on your server. You should be able to query the data using that polygon data. You would have to format the query properly, though.
Lastly, I would encourage you to look into the ESRI SDK for iOS. ESRI provides drawing and sketching tools out of the box. Its not too difficult to use but one downside is that you would have to learn a new API:
http://resources.arcgis.com/en/communities/runtime-ios-sdk/

Resources