iPhone App :show direction using Map

怎甘沉沦 提交于 2019-12-08 04:26:06

问题


in My iPhone App How Can I show directions from current location to End Point?

is there any built in component or facility available on iphone which can show maps and direction using GPS and built in compass?


回答1:


If you mean taking the user to the maps application based on two points, then you can do it like this:

  1. Create an NSURL that looks like this: NSURL *URL = [NSURL URLWithString:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"]; You plug in your starting address and destination (in lat. and long.) appropriately.
  2. Tell your application to open the URL [[UIApplication sharedApplication] openURL:URL];

It should take you to the maps application automatically!




回答2:


try this:-

NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%f,%f&daddr=%f,%f",sourcelocation.latitude,sourcelocation.longitude,destinationlocation.latitude,destinationlocation.longitude];

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



回答3:


NSString *Urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%@&daddr=%@",from_address,to_address];

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

This will give clear direction mentioning the source address and destination address.



来源:https://stackoverflow.com/questions/7605879/iphone-app-show-direction-using-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!