如何在A到B的Xcode上的iPhone

如何在A到B的Xcode上的iPhone

本文介绍了如何在A到B的Xcode上的iPhone iOS 6应用程序中获取方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从iOS更新应用程序< 6使用Google地图。我的应用在地图上有很多针脚,并且当用户点击其中的一个时,iPhone像调用共享应用程序一样调用Google Maps来从当前位置和目标位置获取本地地图应用的方向。在iOS 6中,相同的指示(下面发布)显然会打开Safari,而不是Google Maps。我想写一个if-cycle来检查安装在设备上的iOS:if< 6,没有什么变化,如果iOS> 6然后.....(打开新的苹果地图,并获得方向)。



此处iOS 6之前的操作

   - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];


NSString * addr = [NSString stringWithFormat:@http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale, view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];

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





解决方案我已经使用了如下所示的预处理器代码来定义if循环的条件。

  #define SYSTEM_VERSION_LESS_THAN(v)([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

然后:

  if(SYSTEM_VERSION_LESS_THAN(@6.0)){
NSString * addr = [NSString stringWithFormat:@http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale,view.annotation.coordinate.latitude,view.annotation.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 = Posizione attuale,view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL * url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];


}

它似乎可以工作
再见!


I want to update an app from iOS < 6 that uses Google Maps. My app has a lot of pins on a map, and, when a user taps over one of them, the iPhone call Maps like a shared application to get direction from his current location and the destination with the native Maps App. With iOS 6, the same instructions (posted below) obviously open Safari instead Google Maps. I want to write an if-cycle that checks the iOS installed on the device: if < 6, nothing changed, if iOS > 6 then..... (open new apple maps and get direction there).

Someone can help me please?

Here the Action before iOS 6

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

    [self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];


    NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];

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



}
解决方案

I've used a preprocessor code like this one posted below to define my condition for the if cycle.

#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

Then:

if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
         NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.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=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];


    }

It seems to workBye !

这篇关于如何在A到B的Xcode上的iPhone iOS 6应用程序中获取方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:10