如何在iOS中打开带有方向和语音的Google地图导航Url? [英] How to Open Google Map Navigation Url with Direction and Voice in iOS?

查看:104
本文介绍了如何在iOS中打开带有方向和语音的Google地图导航Url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS的新手我想制作一个包含地图工具包navigation.i想要打开谷歌地图的导航网址,如果用户设备有谷歌地图应用程序的应用程序。如果它不包含,那么我想打开Apple映射在这里,我写了一个像

   - (IBAction)的代码navigationButtonPressed: (id)sender 
{
if([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@comgooglemaps://]])
{
NSString * urlString = [NSString stringWithFormat:@comgooglemaps://?center =%f,%f& zoom = 14& views = traffic,self.latitude,self.longitude];
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:urlString]];
}
else
{
NSString * string = [NSString stringWithFormat:@http://maps.apple.com/?ll=%f,%f,self .latitude,self.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];


但是这里我想打开谷歌地图或苹果地图用户当前位置和所选位置之间的转向是怎么回事可能请给我解决方案对此。 对于Google地图你需要做这样的事情: -



使用此方案请求并显示两个地点之间的路线。您也可以指定交通模式。



参数
saddr:设置路线搜索的起点。这可以是纬度,经度或查询格式的地址。如果它是返回多个结果的查询字符串,则会选择第一个结果。如果该值留空,则将使用用户的当前位置。
daddr:设置路线搜索的终点。与saddr具有相同的格式和行为。
directionsmode:运输方式。可以设置为:驾车,公交,骑自行车或步行。



以下示例URL显示Google NYC和JFK Airport之间的公交路线:



comgooglemaps://?saddr = Google + Inc,+ 8th + Avenue,+ New + York,+ NY& daddr = John + F. + Kennedy + International + Airport,+ Van + Wyck +高速公路,+牙买加,+新+约克& directionsmode =过境



以下是一些额外的例子:

comgooglemaps:// ?SADDR =谷歌,+ 1600 +剧场+大路,+山+景观+ CA + 94043&放大器; DADDR =谷歌+公司+ 345 +矛+街+三+旧金山+ CA&放大器;中心= 37.422185,-122.083898&放大器; zoom = 10



comgooglemaps://?saddr = 2025 + Garcia + Ave,+ Mountain + View,+ CA,+ USA& daddr = Google,+ 1600 +露天剧场+大路,+山+视图,+ CA,+美国+国家& center = 37.423725,-122.0877& directionsmode =行走&放大= 17

请参阅

https://developers.google.com/maps/documentation / ios / urlscheme



对于Apple Map,可以这样做: -
以下示例显示了您将用于提供San之间行车路线的字符串Francisco
和Cupertino:

http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino



请参阅: -



https://developer.apple.com/library/iad/featuredarticles/iPhoneURLScheme_Reference/iPhoneURLScheme_Reference.pdf



这适用于我,只有问题我可以看到与您的查询是准确的经纬度值(那些看起来是一个度纬度经度值,但作为小数纬度经度值传递。



示例
从Downey到Los Angles的路线
NSString * string = [NSString stringWithFormat:@ http://maps.apple.com/ ?daddr =%1.6f,%1.6f& saddr =%1.6f,%1.6f,34.0522300 ,-118.2436800,33.9400100,-118.1325700];





但是对于某些方向,它不起作用,并显示路线不可用





i am newbie in iOS I want to make an app that contain map kit navigation.i want to open navigation url of google map if user device have Google map application. if it is not contain then i want to open Apple map Here i write a code for like as

 -(IBAction)navigationButtonPressed:(id)sender
 {
if ([[UIApplication sharedApplication] canOpenURL:
     [NSURL URLWithString:@"comgooglemaps://"]])
{
    NSString *urlString=[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&zoom=14&views=traffic",self.latitude,self.longitude];
    [[UIApplication sharedApplication] openURL:
     [NSURL URLWithString:urlString]];
}
else
{
    NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/?ll=%f,%f",self.latitude,self.longitude];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
}

But here i want to open google map or apple map with turn by turn direction between User current location and Selected Location how it is Possible Please Give me Solution For this.

解决方案

For Google Map You would need to do something like this:-

Use this scheme to request and display directions between two locations. You can also specify the transportation mode.

Parameters saddr: Sets the starting point for directions searches. This can be a latitude,longitude or a query formatted address. If it is a query string that returns more than one result, the first result will be selected. If the value is left blank, then the user’s current location will be used. daddr: Sets the end point for directions searches. Has the same format and behavior as saddr. directionsmode: Method of transportation. Can be set to: driving, transit, bicycling or walking.

An example URL is below to display transit directions between Google NYC and JFK Airport:

comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=transit

Some additional example are below:

"comgooglemaps://?saddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA+94043&daddr=Google+Inc,+345+Spear+Street,+San+Francisco,+CA&center=37.422185,-122.083898&zoom=10"

"comgooglemaps://?saddr=2025+Garcia+Ave,+Mountain+View,+CA,+USA&daddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA,+United+States&center=37.423725,-122.0877&directionsmode=walking&zoom=17"

Refer to:

https://developers.google.com/maps/documentation/ios/urlscheme

For Apple Map do like this:- The following examples show the strings you would use to provide driving directions between San Francisco and Cupertino:

"http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino"

Refer:-

"https://developer.apple.com/library/iad/featuredarticles/iPhoneURLScheme_Reference/iPhoneURLScheme_Reference.pdf"

This works for me, only issue i can see with your query is accurate lat long values(Those looks to be a degree latitude longitude value but passed as a decimal latitude longitude value.

Example Route from Downey to Los Angles NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/? daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",34.0522300,-118.2436800,33.9400100,-118.1325700];

But for some of the directions it does not work and shows Directions not available

这篇关于如何在iOS中打开带有方向和语音的Google地图导航Url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆