Road with traffic on MKMapView - ios

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

Related

Draw polylines which follow the roads gemoetry

In my app I want to highlight certain roads, which can easily be achieved just by drawing polylines on top of the roads. (I am using the Google Maps SDK, by the way). However these polylines won't follow the road's geometry, they will just connect two coordinates with a straight line. (I have a coordinate for the start of the road which I want to highlight and the end of it). The coordinates won't change, the same roads will be highlighted through out the whole time in the app.
The question is: Is there a way I could draw these polylines not to be straight but to follow the road's geometry? If it's not possible in the SDK, is there a tool on the internet which will connect two coordinates following the roads between them? Because if there is, than I could get the coordinates of those poylines and parse them in my app.
Cheers!
as #Fabian has suggested, if you have a small set of polylines to show in your app, and your app works mostly offline, it would be better to get all the polylines during the development. And there are two ways:
1) through the direction API, you might able to skip all the implementation by using the WEB API, which is meant for webserver.
https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&avoid=highways&mode=bicycling&key=API_KEY
2) or, with the Snap to Road API, which might gives you a better control over your route compare to the direction API. This API is meant to fix the pool GPS data you get from the sensor and snap those on the road.

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 dynamically draw maps

In an iOS application, I want to draw a United States map with states and counties outlined. I also want to draw individual states with counties outlined. I have researched using Shapefiles to do the drawing, but I can't find a good API that translates shapefiles. I have looked into ArcGIS, but it seems most of the drawing they do is web/server based, also without the ability to draw individual states, or outline counties.
Does anyone know of a good iOS API I can use to draw the following maps?
United States with states and counties outlined
Individual state with counties outlined
Take a look at MapBox, it will let you draw these types of maps, then you can pull them in as tiles and overlay them with MapKit.
They also have an iOS SDK, http://mapbox.com/mapbox-ios-sdk/ if you don't want to use MapKit.
I think ArcGIS for iOS is your answer here. The iOS API will allow you to add a MapView to your application.
You can add one or more geoservices to that MapView, as well as local graphic layers.
MapServices are rendered server-side. FeatureServices are rendered client-side. You can also take features (each county or state would be a feature) from the FeatureService and put them into the graphic layer to implement different effects such as selection, outlining...
If you want to have all data stored in the client (the device), then you can embed the json representation of the features and add them to the graphics layer in the MapView, without needing to connect to any geoservice (although geo applications work better when connecting to a server)
Start here: http://developers.arcgis.com/en/ios/sample-code/
This sample looks similar to what you are looking for: http://www.arcgis.com/home/item.html?id=417a0bf9dfda482c8110ebdbde3edd66
This also looks promising: http://developers.arcgis.com/en/ios/guide/cloud-storage-feature-services.htm
All good answers above. The solution that ended up working for me was to simply use an SVG image, drag it into PaintCode and PaintCode gives me all the code to draw the image. A very simple and elegant solution.

Subclassing MKMapView to provide custom maps?

I'd like to provide custom navigation maps in my iOS 6 application. I've tried adding overlay views that shows these custom maps in MKMapView and it didn't work well because it needs a higher zoom level than what Apple's component can provide (the desired zoom level is about 10 screen points per meter in the map).
The question is, is subclassing MKMapView a good way to approach to this? The primary reason is I'd like to take advantage of MKMapView's coordinate conversion functions:
convertCoordinate:toPointToView:
convertPoint:toCoordinateFromView:
convertRegion:toRectToView:
convertRect:toRegionFromView:
Those functions makes it easy to convert screen points to world coordinates (latitude/longitude) and vice-versa.
Thanks in advance!
I don't think you are going to have much luck with subclassing MKMapView. There is a lot going on behind the scenes related to tile loading that you cannot access.
I would guess you would be better served using something along the lines of the MapBox iOS SDK or another similar map engine.
It allows you to specify your own tile sources and has plenty of examples to show you how it is done. It also had functions, like map kit, to handle converting values to and from lat/lon.

What nice map can allow streets on top of polygons

I would like to use something like google, mapquest, bing, or openlayers to try and get something that looks like
http://screencast.com/t/qZejYb0L3Er
where the major streets are unaffected by the polygon overlay.
Can someone point me in the right direction. From the google api documentation it would appear i cant get under the roads so... looking for some help.
You can do it with Google Maps by changing the order of the layers.
This is an API V2 example, but you can achieve the same result with the current version, which is V3.
We ended up using http://www.mapdotnet.com/ with background from open maps. Custom middle cache tiles from shape files stored in SQL, on top we have open street layer (or can use bing)

Resources