Home > Software engineering >  using openURL to jump to Baidu Map app from within an ios app
using openURL to jump to Baidu Map app from within an ios app

Time:11-24

I am using the following API :

[[UIApplication sharedApplication] openURL: options: completionHandler: ];

The argument to openURL is generated by the following example format string :

@"baidumap://map/direction?origin=latlng:%f,%f | name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving"

The app runs smoothly during runtime but fails to invoke baidumap.

Have attached an anonymous fuction to completionHandler :

^(BOOL success) { if (success) NSLog(@"Invoke success = 1"); else NSLog(@"Invoke success = 0"); }

The augument passes in via "BOOL sucess" is always 0.

I suspect that the problem comes from the format string.

Hope that somebody who is familiar with Baidu map API can give me some help.

CodePudding user response:

As stated on the baidumap site you need some escaping :

NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving",currentLatitude, currentLongitude,_shopLat,_shopLon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;

And also to give geographic coordinates for sources and destination

  • Related