【问题标题】:Getting Directions using only Apple map仅使用 Apple 地图获取路线
【发布时间】:2013-02-01 12:43:45
【问题描述】:

我的应用程序中有一个地图视图,我正在使用苹果地图,我阅读了here,Mapkit 可以提供方向详细信息,就像在 Mapview 上我使用当前位置和纬度/经度一样,我希望该用户可以获取从他当前位置到他输入的指定纬度/经度的行车路线,以便当我点击按钮方法或标注方法时,他可以在 nextview 上轻松获取行车路线路线...

-(void)getDirection

所以在下一个视图中,它应该向我显示到那个地方的行车路线,请任何人帮助我解决这个问题,我是初学者,我从来没有对 mapview 做过那么多,谁能给我一些对我很有帮助的提示或代码 sn-p。 或者,如果我可以做类似this 之类的事情,但我不知道如何在我的项目中做到这一点。

【问题讨论】:

  • 您只能启动 Map.app 并指定路线以开始导航。除非您自己编写路线代码,否则您无法在自己的应用中执行此操作。
  • @rckoenes :那么如何编码方向? ..因为我有当前位置和指定的纬度/经度..所以我现在只想要他们的方向..怎么做?
  • 嗯,您需要获取某种数据库,其中包含所有道路和一些复杂的代码来计算路线。 Apple 没有为此提供任何 SDK 方法。您可以使用 google maps API 来获取路线,但如果您能以这种方式使用,则必须检查那里的许可证。

标签: ios map navigation mkpinannotationview apple-maps


【解决方案1】:

使用此代码前两个是目的地纬度经度其他是源 此代码将您重定向到苹果地图上,并在可用时显示路线。

  NSString *urlString = [NSString stringWithFormat:@"http://maps.apple.com/?daddr=%f,%f,&saddr=%f,%f",_desLatitude,_desLongitude,_latitude,_longitude];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

【讨论】:

  • 感谢@user2155906 的回答,但我已经这样做了,因为它是2 月的一个问题。无论如何感谢您的回答!!下面是我的代码。
  • 您在&saddr 之前添加了一个逗号,导致链接错误。
【解决方案2】:
   if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
       NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];

        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];
    }

    else {
        NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];
        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];


    }   
}
else if ([buttonTitle isEqualToString:@"Google Maps"]) {
    NSLog(@"Other 2 pressed");
    //choose existing

    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];

        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];
    }

    else {
        NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];
        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];


    }


} 

其中 pin_lat 和 pin_long 是包含 place 值的浮点值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多