MapKit-Route-Directions icon indicating copy to clipboard operation
MapKit-Route-Directions copied to clipboard

Google changed the API a bit, this is a quick fix.

Open ptxmac opened this issue 14 years ago • 18 comments

ptxmac avatar Nov 01 '10 11:11 ptxmac

fix in UICGRoute.m to get it working :

// NSArray *allKeys = [dictionaryRepresentation allKeys]; NSDictionary *k = [dictionaryRepresentation objectForKey:@"D"]; NSArray *stepDics = [[dictionaryRepresentation objectForKey:@"D"] objectForKey:@"Steps"];

ghost avatar May 31 '11 11:05 ghost

They changed it again?

ptxmac avatar May 31 '11 11:05 ptxmac

i dont know but i had to change these lines to get it to work. couldn't find how to download your fix.. so perhaps i have downloaded the original and fixed the same thing (i'm sorry if that is the case!)

ghost avatar May 31 '11 11:05 ghost

My fix uses the F key instead of D, don't know the significance thou, google maps api's is a bit strange

ptxmac avatar May 31 '11 11:05 ptxmac

it's changed again, look for dictionary with steps key

        NSString *key = @"";
        NSDictionary *dd;

        for (NSString *ky in allKeys) {
            
            if([[dictionaryRepresentation objectForKey:ky] class] == [dd class] && [[dictionaryRepresentation objectForKey:ky] objectForKey:@"Steps"]!=nil){
                key = [ky copy];
                break;
            }

        }

        NSDictionary *k = [dictionaryRepresentation objectForKey:key];

hasnat avatar Jul 11 '11 06:07 hasnat

RouteListViewController is not showing anything. It is completely blank. Please anyone help me find it out.

Thanks for the help in advance. Waiting for early reply...

maksumon avatar Sep 29 '11 10:09 maksumon

It always display 500 geocode error.

shipat8585 avatar Oct 03 '11 11:10 shipat8585

Just found a fix! here it is:

Change the original code in this way:

  1. Comment these lines //NSArray *allKeys = [dictionaryRepresentation allKeys]; //NSDictionary *k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:[allKeys count] - 1]]; //NSArray *stepDics = [k objectForKey:@"Steps"];
  2. Add this line: //Google has changed the key to "pr" that contains the "Steps" dict NSDictionary *k = [dictionaryRepresentation objectForKey:@"pr"];
  3. Add this line: NSArray *stepDics = [[dictionaryRepresentation objectForKey:@"pr"] objectForKey:@"Steps"];

That's all there is to it! Enjoy!!!

Cheers! Radorbit India

radorbit avatar Oct 06 '11 21:10 radorbit

Hi even after implemented the "radorbit" fix the RouteListViewController is not showing anything. It is completely blank. Please anyone help me find it out.

maksumon avatar Oct 09 '11 17:10 maksumon

Has changed API again ? I tryed to fix this code.

UICGRoute#initWithDictionaryRepresentation

//NSArray *allKeys = [dictionaryRepresentation allKeys]; //NSDictionary *k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:[allKeys count] - 1]]; //NSArray *stepDics = [k objectForKey:@"Steps"]; NSDictionary *k = [dictionaryRepresentation objectForKey:@"A"]; NSArray *stepDics = [[dictionaryRepresentation objectForKey:@"A"] objectForKey:@"Steps"];

It worked at the moment.

hmori avatar Oct 13 '11 13:10 hmori

"RouteListViewController is not showing anything. It is completely blank.."

Same thing, any solution?

steve21124 avatar Nov 25 '11 12:11 steve21124

IF found probably a more reliable solution to that instead of continue to change the key, and probably I will add a more reliable at all. This is a beginning it just loop through the dictionaries looking for the right with the "STep" key. Hope this helps. Of course remove the unnecessary lines.

NSSet * setOfKeys = [dictionaryRepresentation keysOfEntriesPassingTest:^(id key, id obj, BOOL * stop){ if ([obj isKindOfClass:[NSDictionary class]]) { for (NSString *keyString in [obj allKeys]) { if ([keyString isEqualToString:@"Steps"]) { *stop=YES; return YES; } } } return NO; }]; NSDictionary * k = [dictionaryRepresentation objectForKey:[setOfKeys anyObject]]; NSArray * stepDics = [k objectForKey:@"Steps"];

Bye, Andrea

DrAma999 avatar Feb 07 '12 10:02 DrAma999

Thanks a lot Andrea! You saved my neck..

I have just a question, I'm getting a lot of Japanese characters, is possible to get rid off them or translate them??

EDIT: I Got it.. chaged the Locale Identifier

Thanks!

afrade avatar May 10 '12 19:05 afrade

Hi afrade, I do not remember quite well it's been a long time. You can find the ideogram in the RootViewController if I remember well, they are just placeholders for addresses, take a look around TableView datasource and delegate methods. Pay attention about two things:

  • (void)webView:(UIWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame; is undocumented, I do not know if apple will accept it
  • (void)setContentToHTMLString:(id)fp8; is private API you cannot use it
  • recently google returns some html codification in the json that the SBJSON lib is unable to parse, you should see an error, try with different address to see it.

I've managed last two, removing all html encoding inside the string-->parsing as written-->show plain text, instead of converting from html using private API. The first is different and little bit complicated because you should modify the javascript part and some delegates around. Ciao

DrAma999 avatar May 11 '12 05:05 DrAma999

I am sorry but i am very new to Xcode, I love this code but I cannot find a way to pass current latitude and longitude as start address, can someone please help?

xcodecs avatar Sep 14 '12 22:09 xcodecs

Guys is this legal with new Ios6? And Google preventing to publish its routes other than Google Maps?

zelin avatar Dec 28 '12 17:12 zelin

Google has again changed the key to "g"

Replace NSArray *stepDics; NSDictionary *k; for (int i = 0; i<allKeys.count; i++) { k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:i]]; if ([k objectForKey:@"Steps"]) { stepDics = [k objectForKey:@"Steps"]; break; } }

with NSDictionary *k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:[allKeys count] - 1]]; NSArray *stepDics = [k objectForKey:@"Steps"];

now if google change the response key it will work :)

SurenderRathore avatar Mar 29 '13 11:03 SurenderRathore

Thanks a lot Andrea!.........

Great effort ....

NAGAVENDRA avatar Jun 01 '13 06:06 NAGAVENDRA