Google SDK Map - Inaccurate Way

I am trying to show the path between two points, but this is not accurate.

if(center.latitude != 0 && center.longitude != 0) { NSString *urlString = [NSString stringWithFormat: @"%@?origin=%f,%f&destination=%f,%f&sensor=true&key=%@", @"https://maps.googleapis.com/maps/api/directions/json", center.latitude, center.longitude, center1.latitude, center1.longitude, KGoogleMapServerKey]; NSError *error; NSDictionary *json =[NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString] options:NSDataReadingUncached error:&error] options:NSJSONReadingMutableContainers error:&error]; if(json[@"routes"] != nil && [json[@"routes"] count] > 0) { GMSPath *path =[GMSPath pathFromEncodedPath:json[@"routes"][0][@"overview_polyline"][@"points"]]; GMSPolyline *singleLine = [GMSPolyline polylineWithPath:path]; singleLine.strokeWidth = 7; singleLine.strokeColor = [UIColor colorWithRed:56.0/255.0 green:163.0/255.0 blue:249.0/255.0 alpha:1.0]; singleLine.map = mapViewGoogle; } 

This is the way I get:

enter image description here

As you can see, the blue line (path) does not go to the destination.
How to fix it?

+6
source share
2 answers

Your route is too long. Each Google Directions API response has a limited number of points. In your example, you got N points, pulled the route with them, and enlarged the mapView to an area where there were only four points.
To always display the exact route, you must recalculate the route after each map scale (including midpoints to keep the route the same).
For example, the full route on your screen has 50 points. You scale the map, so only 4 points are displayed (your screenshot). Now take # 1 as start, # 5 as the finish line and # 2 # 3 # 4 as the middle and send a new request to find the route for these points. You will receive new 50 points, and with them you can more accurately draw this part of the route.

enter image description here

+5
source

The fact is that there is no route for this address, as you can see here: Gmap of your example

I believe your best bet is to use the same approach that Gmaps already uses, I mean using the dotted / dotted polyline from the last point where you get the direction to the actual point.

Here you can find some examples of implementing your type of polyline:

Creating a Dotted Form Using the iOS SDK

+1
source

All Articles