zoukankan      html  css  js  c++  java
  • iOS把经纬度反转为位置信息(街道名等)

    最近做应用用到定位,位置信息可以很容易由CLLocationManager得到(得到的经纬度在中国有偏移,需要纠偏)。但是怎么把特定经纬度的位置信息得到呢,查看了一下资料,发现了CLGeocoder这个类,可以把经纬度反转为位置信息。代码如下:

    -(void)reverseGeocodeForLocation:(CLLocationCoordinate2D)coordinate

    {

        CLLocation *loacation = [[[CLLocation alloc] initWithLatitude:coordinate.latitudelongitude:coordinate.longitude] autorelease];

        CLGeocoder *geoCoder = [[[CLGeocoder alloc] init] autorelease];

        [geoCoder reverseGeocodeLocation:loacation completionHandler:^(NSArray *placemarks, NSError *error)

        {

             //得到的数组placemarks就是CLPlacemark对象数组,这里只取第一个就行

             CLPlacemark *mark = nil;

             if([placemarks count] > 0){

                 id tempMark = [placemarks objectAtIndex:0];

                 if([tempMark isKindOfClass:[CLPlacemark class]])

                 {

                     mark = tempMark;

                 }

                 //具体业务逻辑,CLPlacemark的属性有很多,包括了街道名等相关属性

             }             

         }];

    }

     

  • 相关阅读:
    P4910 帕秋莉的手环
    P3216 [HNOI2011]数学作业
    洛谷 P2894 [USACO08FEB]酒店
    [网络流24题]魔术球问题
    [网络流24题]飞行员配对方案问题
    [网络流24题]最小路径覆盖问题
    洛谷 P1503鬼子进村
    BZOJ 3631: [JLOI2014]松鼠的新家
    洛谷 P2922 [USACO08DEC]秘密消息Secret Message
    洛谷 P1379 八数码难题
  • 原文地址:https://www.cnblogs.com/vicstudio/p/3107211.html
Copyright © 2011-2022 走看看