最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS中定位當(dāng)前位置坐標(biāo)及轉(zhuǎn)換為火星坐標(biāo)的方法

 更新時(shí)間:2016年02月27日 09:18:45   作者:常思過(guò)  
這篇文章主要介紹了iOS中獲取當(dāng)前位置坐標(biāo)及轉(zhuǎn)換為火星坐標(biāo)的方法,這里的火星坐標(biāo)指的是我國(guó)專(zhuān)門(mén)研制的一種加密的坐標(biāo)系統(tǒng)...需要的朋友可以參考下

定位和位置信息獲取
定位和反查位置信息要加載兩個(gè)動(dòng)態(tài)庫(kù) CoreLocation.framework 和 MapKit.framework 一個(gè)獲取坐標(biāo)一個(gè)提供反查

復(fù)制代碼 代碼如下:

// appDelgate.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
 
@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate,MKReverseGeocoderDelegate>
 
@property (strong, nonatomic) UIWindow *window;
 
@end

 
復(fù)制代碼 代碼如下:

#import "AppDelegate.h"
 
 
@implementation AppDelegate
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    button.frame = CGRectMake(0, 100, 100, 30);
    [button setTitle:@"定位" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, 320, 30)];
    label.tag = 101;
    label.text = @"等待定位中....";
    [self.window addSubview:label];
    [label release];
    [self.window addSubview:button];
    return YES;
 
}
 
-(void) test {
    
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    // 設(shè)置定位精度,十米,百米,最好
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    locationManager.delegate = self;
    
    // 開(kāi)始時(shí)時(shí)定位
    [locationManager startUpdatingLocation];
}
 
// 錯(cuò)誤信息
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"error");
}
 
// 6.0 以上調(diào)用這個(gè)函數(shù)
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    
    NSLog(@"%d", [locations count]);
    
    CLLocation *newLocation = locations[0];
    CLLocationCoordinate2D oldCoordinate = newLocation.coordinate;
    NSLog(@"舊的經(jīng)度:%f,舊的緯度:%f",oldCoordinate.longitude,oldCoordinate.latitude);
    
//    CLLocation *newLocation = locations[1];
//    CLLocationCoordinate2D newCoordinate = newLocation.coordinate;
//    NSLog(@"經(jīng)度:%f,緯度:%f",newCoordinate.longitude,newCoordinate.latitude);
    
    // 計(jì)算兩個(gè)坐標(biāo)距離
    //    float distance = [newLocation distanceFromLocation:oldLocation];
    //    NSLog(@"%f",distance);
    
    [manager stopUpdatingLocation];
    
    //------------------位置反編碼---5.0之后使用-----------------
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:newLocation
                   completionHandler:^(NSArray *placemarks, NSError *error){
                       
                       for (CLPlacemark *place in placemarks) {
                           UILabel *label = (UILabel *)[self.window viewWithTag:101];
                           label.text = place.name;
                           NSLog(@"name,%@",place.name);                       // 位置名
//                           NSLog(@"thoroughfare,%@",place.thoroughfare);       // 街道
//                           NSLog(@"subThoroughfare,%@",place.subThoroughfare); // 子街道
//                           NSLog(@"locality,%@",place.locality);               // 市
//                           NSLog(@"subLocality,%@",place.subLocality);         // 區(qū)
//                           NSLog(@"country,%@",place.country);                 // 國(guó)家
                       }
                       
                   }];
    
}
 
// 6.0 調(diào)用此函數(shù)
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"%@", @"ok");
}
 
 
@end

轉(zhuǎn)換為火星坐標(biāo)
這個(gè)寫(xiě)的公共類(lèi)叫做:GPScombineClass類(lèi)主要展示GPS位置的定位,GPS坐標(biāo)的獲取,然后從手機(jī)坐標(biāo)轉(zhuǎn)換成火星坐標(biāo),繼而在需要的情況下,由火星轉(zhuǎn)百度 ,百度轉(zhuǎn)火星的詳細(xì)算法;

在GPScombineClass.h中

復(fù)制代碼 代碼如下:

#import <Foundation/Foundation.h>

#import <CoreLocation/CoreLocation.h>

#import "CSqlite.h"

#import <MapKit/MapKit.h>

@interface GPScombineClass : NSObject<MKMapViewDelegate>{

    CLLocationManager *locationManager;

    CSqlite *m_sqlite;

   

    UILabel *m_locationName;

    MKMapView *mainMapView;

@public CLLocationCoordinate2D baidulocation;

    CLLocationCoordinate2D deleeverLocation;

}

-(void)OpenGPSmapView;

//在地圖上放上自己的位置--外接接口

-(void)setMyMapPonitByMKMapView:(MKMapView *)MyMap;

@end


復(fù)制代碼 代碼如下:

@interface POI : NSObject <MKAnnotation> {

   

    CLLocationCoordinate2D coordinate;

    NSString *subtitle;

    NSString *title;

}

 

@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;

@property (nonatomic,retain) NSString *subtitle;

@property (nonatomic,retain) NSString *title;

 

-(id) initWithCoords:(CLLocationCoordinate2D) coords;

 

@end


 

在GPScombineClass.m中

復(fù)制代碼 代碼如下:

#import "GPScombineClass.h"

const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

@implementation GPScombineClass

-(void)OpenGPSmapView{

    m_sqlite = [[CSqlite alloc]init];

    [m_sqlite openSqlite];

    if ([CLLocationManager locationServicesEnabled]) { // 檢查定位服務(wù)是否可用

        locationManager = [[CLLocationManager alloc] init];

        locationManager.delegate = self;

        locationManager.distanceFilter=0.5;

        locationManager.desiredAccuracy = kCLLocationAccuracyBest;

        [locationManager startUpdatingLocation]; // 開(kāi)始定位

    }

   

    NSLog(@"GPS 啟動(dòng)");

}

 

// 定位成功時(shí)調(diào)用

- (void)locationManager:(CLLocationManager *)manager

    didUpdateToLocation:(CLLocation *)newLocation

           fromLocation:(CLLocation *)oldLocation

{

    CLLocationCoordinate2D mylocation = newLocation.coordinate;//手機(jī)GPS

   

    mylocation = [self zzTransGPS:mylocation];///轉(zhuǎn)換成火星GPS

    deleeverLocation=mylocation;

    baidulocation=[self hhTrans_bdGPS:mylocation];//轉(zhuǎn)換成百度地圖

     /*

    //顯示火星坐標(biāo)

    [self SetMapPoint:mylocation MKMapView:mainMapView];

  

    /////////獲取位置信息

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray* placemarks,NSError *error)

     {

         if (placemarks.count >0   )

         {

             CLPlacemark * plmark = [placemarks objectAtIndex:0];

            

             NSString * country = plmark.country;

             NSString * city    = plmark.locality;

            

            

             NSLog(@"%@-%@-%@",country,city,plmark.name);

             self->m_locationName.text =plmark.name;

             NSLog(@"%@",self->m_locationName);

         }

        

         NSLog(@"%@",placemarks);

        

     }];

   

    //[geocoder release];

    */

}

// 定位失敗時(shí)調(diào)用

- (void)locationManager:(CLLocationManager *)manager

       didFailWithError:(NSError *)error {

    NSLog(@"定位失敗");

}

 

//把手機(jī)GPS坐標(biāo)轉(zhuǎn)換成火星坐標(biāo) (google坐標(biāo))

-(CLLocationCoordinate2D)zzTransGPS:(CLLocationCoordinate2D)yGps

{

    int TenLat=0;

    int TenLog=0;

    TenLat = (int)(yGps.latitude*10);

    TenLog = (int)(yGps.longitude*10);

    NSString *sql = [[NSString alloc]initWithFormat:@"select offLat,offLog from gpsT where lat=%d and log = %d",TenLat,TenLog];

    NSLog(sql);

    sqlite3_stmt* stmtL = [m_sqlite NSRunSql:sql];

    int offLat=0;

    int offLog=0;

    while (sqlite3_step(stmtL)==SQLITE_ROW)

    {

        offLat = sqlite3_column_int(stmtL, 0);

        offLog = sqlite3_column_int(stmtL, 1);

       

    }

   

    yGps.latitude = yGps.latitude+offLat*0.0001;

    yGps.longitude = yGps.longitude + offLog*0.0001;

    return yGps;

   

   

}

//在地圖上放上自己的位置--外接接口

-(void)setMyMapPonitByMKMapView:(MKMapView *)MyMap{

 //顯示火星坐標(biāo)

    [self SetMapPoint:deleeverLocation MKMapView:MyMap];

    MyMap=mainMapView;

}

//在地圖上放上自己的位置

-(void)SetMapPoint:(CLLocationCoordinate2D)myLocation MKMapView:(MKMapView *)mapView

{

//    POI* m_poi = [[POI alloc]initWithCoords:myLocation];

//   

//    [mapView addAnnotation:m_poi];

   

    MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };

    theRegion.center=myLocation;

    [mapView setZoomEnabled:YES];

    [mapView setScrollEnabled:YES];

    theRegion.span.longitudeDelta = 0.01f;

    theRegion.span.latitudeDelta = 0.01f;

    [mapView setRegion:theRegion animated:YES];

   

}

 

//把火星坐標(biāo)轉(zhuǎn)換成百度坐標(biāo)

-(CLLocationCoordinate2D)hhTrans_bdGPS:(CLLocationCoordinate2D)fireGps

{

    CLLocationCoordinate2D bdGps;

    double huo_x=fireGps.longitude;

    double huo_y=fireGps.latitude;

    double z = sqrt(huo_x * huo_x + huo_y * huo_y) + 0.00002 * sin(huo_y * x_pi);

    double theta = atan2(huo_y, huo_x) + 0.000003 * cos(huo_x * x_pi);

    bdGps.longitude = z * cos(theta) + 0.0065;

    bdGps.latitude = z * sin(theta) + 0.006;

    return bdGps;

}

#pragma mark 顯示商品信息

#pragma mark

-(void)showPurchaseOnMapByLocation:(CLLocationCoordinate2D)baiduGPS MKMapView:(MKMapView*)myMapView{

    CLLocationCoordinate2D googleGPS;

    googleGPS=[self hhTrans_GCGPS:baiduGPS];//轉(zhuǎn)換為百度

    [self SetPurchaseMapPoint:googleGPS MKMapView:myMapView];

}

//把百度地圖轉(zhuǎn)換成谷歌地圖--火星坐標(biāo)

-(CLLocationCoordinate2D)hhTrans_GCGPS:(CLLocationCoordinate2D)baiduGps

{

    CLLocationCoordinate2D googleGps;

    double bd_x=baiduGps.longitude - 0.0065;

    double bd_y=baiduGps.latitude - 0.006;

    double z = sqrt(bd_x * bd_x + bd_y * bd_y) - 0.00002 * sin(bd_y * x_pi);

    double theta = atan2(bd_y, bd_x) - 0.000003 * cos(bd_x * x_pi);

    googleGps.longitude = z * cos(theta);

    googleGps.latitude = z * sin(theta);

    return googleGps;

}

 

-(void)SetPurchaseMapPoint:(CLLocationCoordinate2D)myLocation MKMapView:(MKMapView *)mapView

{

    POI* m_poi = [[POI alloc]initWithCoords:myLocation];

  
    [mapView addAnnotation:m_poi];
 

    MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };

    theRegion.center=myLocation;

    [mapView setZoomEnabled:YES];

    [mapView setScrollEnabled:YES];

    theRegion.span.longitudeDelta = 0.01f;

    theRegion.span.latitudeDelta = 0.01f;

    [mapView setRegion:theRegion animated:YES];}

@end

相關(guān)文章

  • iOS第三方框架二維碼生成與掃描

    iOS第三方框架二維碼生成與掃描

    這篇文章主要為大家詳細(xì)介紹了iOS第三方框架二維碼生成與掃描,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • iOS 自定義返回按鈕保留系統(tǒng)滑動(dòng)返回功能

    iOS 自定義返回按鈕保留系統(tǒng)滑動(dòng)返回功能

    這篇文章主要介紹了iOS 自定義返回按鈕,保留系統(tǒng)滑動(dòng)返回功能,實(shí)現(xiàn)方法非常簡(jiǎn)單,具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-01-01
  • 詳解iOS開(kāi)發(fā)中app的歸檔以及偏好設(shè)置的存儲(chǔ)方式

    詳解iOS開(kāi)發(fā)中app的歸檔以及偏好設(shè)置的存儲(chǔ)方式

    這篇文章主要介紹了iOS開(kāi)發(fā)中app的歸檔以及偏好設(shè)置的存儲(chǔ)方式,示例代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2015-12-12
  • iOS中實(shí)現(xiàn)圖片自適應(yīng)拉伸效果的方法

    iOS中實(shí)現(xiàn)圖片自適應(yīng)拉伸效果的方法

    圖片拉伸在移動(dòng)開(kāi)發(fā)中特別常見(jiàn),比如常用的即時(shí)通訊應(yīng)用中的聊天氣泡就需要根據(jù)文字長(zhǎng)度對(duì)背景圖片進(jìn)行拉伸自適應(yīng)。下面這篇文章主要給大家介紹了iOS中實(shí)現(xiàn)圖片自適應(yīng)拉伸效果的方法,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-03-03
  • 用iOS模擬器安裝App的方法

    用iOS模擬器安裝App的方法

    下面小編就為大家分享一篇用iOS模擬器安裝App的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • iOS新增繪制圓的方法實(shí)例代碼

    iOS新增繪制圓的方法實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于iOS新增繪制圓的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位iOS開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • iOS仿高德首頁(yè)推拉效果實(shí)例代碼

    iOS仿高德首頁(yè)推拉效果實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于iOS仿高德首頁(yè)推拉效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-11-11
  • iOS - UIButton(UIEdgeInsets)/設(shè)置button上的文字和圖片上下垂直居中對(duì)齊

    iOS - UIButton(UIEdgeInsets)/設(shè)置button上的文字和圖片上下垂直居中對(duì)齊

    這篇文章主要介紹了iOS - UIButton(UIEdgeInsets)/設(shè)置button上的文字和圖片上下垂直居中對(duì)齊的相關(guān)資料,需要的朋友可以參考下
    2015-09-09
  • IOS給圖片添加水印(兩種方式)

    IOS給圖片添加水?。▋煞N方式)

    為了防止自己辛苦做的項(xiàng)目被別人盜走,采取把圖片添加水印,在此表示圖片的獨(dú)一無(wú)二。加水印不是要在上面添加上幾個(gè)Label,而是我們要把字畫(huà)到圖片上成為一個(gè)整體,下面這篇文章主要介紹IOS給圖片添加水印,有需要的小伙伴可以來(lái)參考下
    2015-08-08
  • Unity3d發(fā)布IOS9應(yīng)用時(shí)出現(xiàn)中文亂碼的解決方法

    Unity3d發(fā)布IOS9應(yīng)用時(shí)出現(xiàn)中文亂碼的解決方法

    這里給大家分享的是使用UNity3d發(fā)布IOS9應(yīng)用的時(shí)候,遇到出現(xiàn)中文亂碼的現(xiàn)象的解決方法,核心內(nèi)容非常簡(jiǎn)單就是批量修改NGUI的label字體,下面把代碼奉上。
    2015-10-10

最新評(píng)論

泗洪县| 米林县| 高要市| 巴青县| 洛南县| 文山县| 昌图县| 平顶山市| 雷州市| 宁海县| 饶阳县| 筠连县| 当涂县| 古浪县| 嘉荫县| 宜宾市| 沁源县| 诏安县| 冷水江市| 剑川县| 克山县| 德阳市| 兴安盟| 秭归县| 临沧市| 南川市| 仲巴县| 柞水县| 华宁县| 腾冲县| 威海市| 长治县| 长丰县| 凉城县| 合阳县| 福海县| 永昌县| 长乐市| 西青区| 格尔木市| 富平县|