ios6 ios5 調用系統地圖

在IOS6.0系統後,蘋果自己綁定了自家的地圖包,因此兼容IOS5.0與IOS6.0地圖導航,需要分兩個步驟
1.首先#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
用來獲取手機的系統,判斷系統是多少
2.地圖導航代碼

 if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {//6.0以下,調用googleMap

        NSLog(@"6.0以下,調用googleMap");

        //注意經緯度不要寫反了

        NSString * loadString=[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@,%@&daddr=%@,%@",self.myPositionWeiduString,self.myPositionJinduString,yweiduString,xjinduString];

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


   }else{

            CLLocationCoordinate2D to;

            //要去的目標經緯度

       to.latitude = [yweiduString floatValue];

       to.longitude = [xjinduString floatValue];

       MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];//調用自帶地圖(定位)

       //顯示目的地座標。畫路線

       MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[[MKPlacemark alloc] initWithCoordinate:toaddressDictionary:nil] autorelease]];

       toLocation.name = self.shopNameStirng;

       [MKMapItem openMapsWithItems:[NSArray arrayWithObjects:currentLocation, toLocation, nil]

                      launchOptions:[NSDictionary dictionaryWithObjects:[NSArrayarrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber numberWithBool:YES], nil]

                                     

                                                                forKeys:[NSArrayarrayWithObjects:MKLaunchOptionsDirectionsModeKeyMKLaunchOptionsShowsTrafficKeynil]]];

       

       [toLocation release];

   

   }

發佈了19 篇原創文章 · 獲贊 9 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章