Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2012, 01:16 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 114
TelTikky is on a distinguished road
Default Route parsing error (google API)

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?
TelTikky is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
18 members and 381 guests
Apptronics RBC, Atatator, chiataytuday, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, kukat, LunarMoon, MAMN84, n00b, pbart, reficul, Retouchable, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0