creating predefined regions in apple's MapKit - ios

I am new to iOS programming (obj c) and would like to create a feature for my app. I have divided (in photoshop) the world's coastlines into 204 separate regions. I would like to set up these regions in Apple's MapKit so that when a user is in any of these regions, my app will know which region they are in.
I realize this is a longer exercise, but I am only hoping that someone can point me in the right direction with either some basic code or what to search for.
To be clear, for now, just want to be able to draw (or define) the regions in MapKit
Thanks

Have a look at this tutorial:
http://www.raywenderlich.com/30001/overlay-images-and-overlay-views-with-mapkit-tutorial
You'll find an example on how to store your regions in the app and how to show them on the map.

Related

How manage when several annotations has similar or the same coordinates and want to show them?

I have an app (iPhone) that uses MapKit and users can create things on the map (annotations in the remote database, with latitude and longitude).
Problem is that very often users put things in the same building, very close, even in the same coordinates. So you only see the most up-to-date annotation unless you tap it and another is shown, but the usability of this is horrible. No users realize they can do that.
Therefore I guess a way to group close points and when tap, show all of them. It seems the first step can be done with clusters and I see several libraries for iOS for that:
http://cocoapods.org/?q=on%3Aios%20cluster
I would like to know if you have any idea or suggestion to solve the second problem, or the whole problem.
Thanks in advance.
Depending upon the clustering library used, you may be able to get the clustered region that is represented. Then, upon cluster marker tap, you could zoom to that region.
The JS library Leaflet has this behavior so you can see what it's like:
http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-zoomtobounds.html
I realize this is a JS library not ObjC, but just linking it for demo purposes.

iOS MapKit - defining irregular touchable regions

I'm working on an app that lets a user select locations on a map. The entire map is subdivided into irregular regions (administrative boundaries), and when a user touches a point on a map, I need to be able to figure out which region the point belongs to. Just to clarify, there is no finite set of points for a user to choose from, they just tap anywhere on the map.
What is the best way to achieve this? I have been looking at MKPolygon class but cannot really figure out if this is the way to go. If it is, would I be using intersectsMapRect: method of the MKOverlay protocol to check for a match? Are there any good tutorials on this kind of map operations?
A good approach here might be the MapBox iOS SDK and it's RMInteractiveSource, which is designed for this. Check out this sample app which shows interactive regions.
This is done by a space-optimized, offline-capable key-value store of sorts that keys pixels at varying zoom levels to arbitrary content values (region name, data, imagery, etc.)
In MapKit proper, you'll need some sort of spatial analysis (maybe Spatialite?) to determine intersections between points touched and irregularly-shaped regions.

MKMapView clustering if too many Map Pins nearby

I'm wondering if any of you knows a method (library, category, etc.) to cluster iOS MapAnnotations if there are many of them at the same location (e.g. 4 pieces in about 10m).
It doesn't matter to zoom in because they are still overlapping. I've already tried https://github.com/applidium/ADClusterMapView (and sombe other libs) but all of them are made for showing clusters in zoom-out-scenarios. None of them really respect the distance between annotations when zoomed in.
I'm working on an app with an offline-db so a server-side solution is not an option.
thank you for your help!
You don't need 3rd party framework's anymore. iOS 11 has native clustering support.
You need to implement mapView:clusterAnnotationForMemberAnnotations: method.
Get more details in the Apple example: https://developer.apple.com/sample-code/wwdc/2017/MapKit-Sample.zip
You should have a look into CCHMapClusterController project, looks exactly like something you are looking for.
One alternative is the MapBox iOS SDK, which is an open source (BSD) library replicating MapKit behavior. It does both annotation clustering and offline map layers.
http://mapbox.com/mobile

How to wrap locations that are close to each other in a single marker with Mapkit?

I am looking for a good and fast way to wrap locations that are in a specific range on a MKMapView in a single marker. Clicking on that marker brings you closer to the center point of this locations. You can see what I mean on the picture below.
mc donalds app - map sample screen
My first thought was to check a specific pixel range for each marker, hide the ones that are closer than X pixels to each other and get the center of them to create a new marker.
Did anyone of you ever did something similar?
There's a demo from WDC 11 or 10 that does exactly that, and coalesces based on proximity, not grid. Much better looking than DTCluster.
After a while of searching an testing, I found several frameworks for this like:
REVClusterMap, SuperPin, DTClusterMaker and a lot more. At the moment I stick with "REMarkerClusterer". It's pretty simple to implement and is free (MIT License)
https://github.com/romaonthego/REMarkerClusterer
Here is a nice article about clustering:
http://applidium.com/en/news/too_many_pins_on_your_map/
If someone else has good frameworks for this in his bookmarks/github-list, please post it here. I sill would like to see them ...

Road with traffic on MKMapView

I have a question about the MKMapView component. I saw that on the native "Map" iOS app, we can draw the roads between different points and we can display the traffic for those roads. Well, that's exactly what I want to do for my app :)
So, I have two questions :
1) Firstly, how can I draw roads on a map. I read a lot of things about MKOverlay, about some samples which do that with JavaScript in UIWebView but what's the best way to do this ?
2) How can I know the traffic on a particularly road ? In order to draw the road in green, orange or red.
Thanks a lot !
Regards,
Sébastien ;)
Unfortunately by now CLGeocoder class from iOS 5 is just supporting to process address to geolocation transformation and reverse. It means to find address around the geocode you have or to find geocode of the address you provide. There are no possibilities access road graph to create routes (to select and draw roads precisely) and moreover to control traffic on the exact place. The only things you can do with standard tools is to draw overlays on the MKMapView with your own data.
To achieve the results you want I would offer to use the third party resources, Google Maps API for example, and use UIWebView to present a customized map. Google Maps JavaScript API v3 TrafficLayer

Resources