简体   繁体   English

通过iPhone中的safari中的应用程序打开谷歌地图

[英]Open google maps through app in safari in iPhone

I want to open the google maps through my app to get the direction with source address equal to my current location and destination address is my string.I have used the below code,i am able to open the app but not able to get the direction. 我想通过我的应用程序打开谷歌地图,以获得源地址等于我当前位置的方向,目的地址是我的字符串。我使用下面的代码,我能够打开应用程序,但无法获得方向。

 NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=My+Location&daddr=%@", [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

By using these line of code, i am able to open the app but the map is not taking the current location,destination address is there. 通过使用这些代码行,我可以打开应用程序,但地图没有占用当前位置,目的地址就在那里。

I have used this also by passing current location latitude and longitude but this also showing current location lat and long to 0.0000 both. 我也通过传递当前位置纬度和经度来使用它,但这也显示当前位置lat和长到0.0000两者。

  NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%1.6f,%1.6f&daddr=%@",
                         coordinate.latitude, coordinate.longitude,
                         [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

This worked for me: 这对我有用:

NSString *coordinateString1 = [NSString stringWithFormat:@"%f,%f", coordinate1.latitude, coordinate1.longitude];
NSString *coordinateString2 = [NSString stringWithFormat:@"%f,%f", coordinate2.latitude, coordinate2.longitude];
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@&daddr=%@",coordinateString1,coordinateString2]];
[[UIApplication sharedApplication] openURL: URL];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM