I am trying to draw a route between two points. A lot of the times it works, but sometimes I get a route like this:
Rest assured, my car has not learnt to swim and there is no bridge across the river along the route.
The beginning and end points are correct, just part of the route is wrong.
I have attached the code for parsing the route.
Code:
- (void *) decodePolyline:(NSString *)encodedPoints
{
NSString *escapedEncodedPoints = [encodedPoints stringByReplacingOccurrencesOfString:@"\\\\" withString:@"\\"];
int len = [escapedEncodedPoints length];
NSMutableArray *waypoints = [[NSMutableArray alloc] init];
int index = 0;
double lat = 0;
double lng = 0;
while (index < len) {
char b;
int shift = 0;
int result = 0;
//printf("b is: %c\n", [escapedEncodedPoints characterAtIndex:index]);
do {
if(index >= len)
break;
b = [escapedEncodedPoints characterAtIndex:index++] - 63;
result |= (b & 0x1f) << shift;
shift += 5;
}while (b >= 32);
//while (b >= 0×20);
double dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
if(index >= len)
break;
b = [escapedEncodedPoints characterAtIndex:index++] - 63;
result |= (b & 0x1f) << shift;
shift += 5;
}while (b >= 32);
//while (b >= 0×20);
double dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
lng += dlng;
double finalLat = lat * 1e-5;
double finalLong = lng * 1e-5;
CLLocationCoordinate2D currentLocation = {finalLat, finalLong};
MKMapPoint point = MKMapPointForCoordinate(currentLocation);
pointArray[totalPoints++] = point;
}
}
Has anyone ever experienced the same problem before, if so how to solve it?