How to get MKPolylines follow the roads properly in MKMapView (iOS)? - ios

)
I'm trying to put a direction polyline on a MKMapView in my iOS project, using Google Directions API. I used the code found in this blog : http://iosguy.com/2012/05/22/tracing-routes-with-mapkit/ , which works quite well.
But the problem I find is that the polyline do not follow the roads, instead it draws lines straight from one point to another :-(
Can anyone please help me to make it follow the roads ? Thanks :-)

Instead of using the coordinates of the route steps, you can use the *overview_polyline* element of the Google Directions response to draw a smooth line following the roads. You can use this code to decode the polyline string: https://gist.github.com/3770235
edit: I erroneously made the assumption you where using the steps coordinates, as that is usually the cause of these straight lines, but the link you post already uses the *overview_polyline*. In that case my answer is probably not solving your problem. Decoding the polyline as a category on MKPolyline could be a nice addition to your code though.

Related

Show only polyline

I am working on an activity tracker, at the end of the activity I have a map where I draw the polyline of the users route, I want to show only the polyline or at least draw a shadow in the map like Nike+Run does, anyone know if that's possible?, I already searched but I couldn't find out how to do it.
Edit:
Something like this
What you are looking for is MKPolyline. Here is the documentation https://developer.apple.com/reference/mapkit/mkpolyline and this tutorial might be helpful to implement http://pinkstone.co.uk/how-to-draw-an-mkpolyline-on-a-map-view/. Its in Obj C should be easy enough reimplement in Swift.

Google maps iOS SDK level of detail polylines

I am using the Google Maps iOS SDK to draw a list of polylines. The polylines come from a server, and for each next polyline, the starting point corresponds with the end point of the previous polyline.
I notice that Google Maps changes the level of detail of the polylines at different zoom levels, probably an optimisation thing. This results in small gaps between the several polylines at lower zoom levels.
The reasons behind splitting a polyline up in several smaller lines are not up to me, this is what the system defines for me. I know I may be able to combine the several polylines into one single large polyline, but I was wondering: does the SDK allow the setting for this level of detail? Or is there maybe another fix?
Zoomed out, notice the gaps:
Almost fully-zoomed in, the gaps are nearly gone:
I have found no answer so far, so what I did, was traversing all geo-coordinates in-order (luckily my data-structure allows this), collect them in an array, encode this array to a Google Encoded Polyline (GEP) as per https://gist.github.com/mmdumi/3999640, and then display this on the map using [GMSPolyLine polylineWithPath:]. As far as I can tell, there is no way to instantiate a GMSPolyLine other than using a GEP.
I have found no answer too, but, there are two ways :
You can draw the entire line like a for sentence and draw, for example :
path.add(CLLocationCoordinate2D(latitude: latitude_,longitude: longitude_))
let polyline = GMSPolyline(path: path)
polyline.strokeColor = .red
polyline.map = mapView
polyline.strokeWidth = 2
or
https://github.com/raphaelmor/Polyline

Simple marker clustering on apple map

Hello I want to do Pin point's clustering on apple map. What is the possible solutions of it.Now the apple map with one pin point is display on my screen. What is the code after it for Pin point's grouping. Thanks in advance
A possible (and successful, I'm using it at work) solution for clustering/displaying lots of points on a map is
http://robots.thoughtbot.com/how-to-handle-large-amounts-of-data-on-maps

IOS MKMapView sidewalk

Im working with Mapkit and I trying to draw a line in the "sidewalks" (border of the street),right now I'm looking for ideas on how I could start this task, thanks for your help.
notes: I know how to works with mkpolyline and coordinates
http://s30.postimg.org/7rnmdjzu9/mapa.png
You do not have access to the information that qualifies as a road inside the MKMapView. so, in order to be able to draw into the border of the street you will need to access the information that qualifies as a street (the coordinates of the road) or analyzing the view and changing the specific color represented by the border of the street (this is not public API, you will need to dig around the view hierarchy).

Creating a new MKPolygon from two intersecting polygons

I know that there is exactly one specific question that talks about this but its a bit old and I wanted to get a little more technical about it if possible.
First of all take a look at this screenshot: https://www.dropbox.com/s/f94q3qaxrog0ec9/intersections.png
Want I want to have happen is say "I see where they both intersect and where that happens I do not want to draw those 'parts' of the polygon". In this case i would like to draw both polygons but not draw the 'path' of the yellow polygon that is inside the orange polygon. This include not only the line but the fill color as well.
Obviously this gets tricky because you aren't always going to have exact points along the path of each polygon that intersect exactly with other points along another polygon path. As you can see from this screenshot, in order to make this possible, I think, I need to get the points back where they do intersect.
After that and assuming that I can do this, I do not know if there is a way to use the CGPathRef class to do what i need to do. Obviously I am going to have re-create a polygon but according to the docs you cant fill it in unless it is a closed path. So how do you fill in the polygon that is not interesecting without closing the path??
The only thing that i can think of would be to "hide" the parts of the polygon that intersect but unsure how to do this. Can anyone offer any help/insight to this problem??
Here you go. I wrote an Objective-C wrapper around Alan's GPC library. Check out MKPolygon-GPC
Ok guys! well i went off and created my own MKPolygon category to solve what i needed to solve. I hope it is also useful to others!
the github link is: https://github.com/geeksweep/MKPolygon-GSPolygonIntersections
After days of investigation, here is the solution I found for Swift 4:
1) Go here and clone the project
2) Drag and drop the following in your project:
- MKPolygon+GPC.m
- MKPolygon+GPC.h
- gpc232 (folder)
3) Create a bridging header (here is a tutorial)
4) Open your bridging header file and add the following :
#import "MKPolygon+GPC.h"
5) In your View Controller , use this method to union your two Polygons :
let mergedPolygon = polygon1.fromUnion(with:polygon2)
NOTE : there is a crash in the current library, I fixed it but I am waiting my pull request to be reviewed. Thanks to SunGard-Labs for the framework !

Resources