美文网首页
苹果地图 地理编码 反地理编码

苹果地图 地理编码 反地理编码

作者: mayday2024 | 来源:发表于2015-05-31 17:16 被阅读624次

CoreLocation.framework 要用到这个框架

import <CoreLocation/CoreLocation.h>

地图编码 是 向苹果发送一个地名 返回详细的地名

  #import "ViewController.h"
            #import <CoreLocation/CoreLocation.h>

            @interface ViewController ()

            /**
             *  地理编码对象
             */
            @property (nonatomic,strong) CLGeocoder * geocoder;

            @end

            @implementation ViewController

            - (void)viewDidLoad {
                [super viewDidLoad];
                // Do any additional setup after loading the view, typically from a nib.
                self.geocoder = [[CLGeocoder alloc] init];
                
                
                // 向苹果服务器发送网络请求,获取 "地名" 的详细信息
                //广州图书馆
                [self.geocoder geocodeAddressString:@"浸潭镇" completionHandler:^(NSArray *placemarks, NSError *error) {
                    //此block是在主线程调用
                    NSLog(@"%@",[NSThread currentThread]);
                    if (!error) {
                        // CLPlacemark 位置标记
                        for (CLPlacemark *placemark in placemarks) {
                            NSLog(@"成功 %@",[placemark class]);
                            
                            NSLog(@"地理名称%@",placemark.name);
                            NSLog(@"街道名%@",placemark.thoroughfare);
                            NSLog(@"国家%@",placemark.country);
                            NSLog(@"城市%@",placemark.locality);
                            NSLog(@"区: %@",placemark.subLocality);

                            NSLog(@"地址%@",placemark.addressDictionary);
                            NSLog(@"=======\n");
                        }
                    }else{
                        NSLog(@"%@",error);
                    }
                    
                }];
            }
   @end

反地理编码 是 向苹果发送一个经纬度 返回详细的地名
对象懒加载

import "ViewController.h"

        #import <CoreLocation/CoreLocation.h>

        @interface ViewController ()
        @property (nonatomic,strong) CLGeocoder * geocoder;
        @end



        @implementation ViewController


        -(CLGeocoder *)geocoder{
            if (!_geocoder) {
                _geocoder = [[CLGeocoder alloc] init];
            }
            
            return _geocoder;
        }

        - (void)viewDidLoad {
            [super viewDidLoad];
            // Do any additional setup after loading the view, typically from a nib.
            
            //反地理编码: 把 "经纬" 转化成详细的地理信息
            
            //广州花城广场: 经度 113.324675 纬度 23.124103
            CLLocation *loc = [[CLLocation alloc] initWithLatitude:23.124103 longitude:113.324675];
            
            
            [self.geocoder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) {
                //此block是在主线程调用
                NSLog(@"%@",[NSThread currentThread]);
                if (!error) {
                    // CLPlacemark 位置标记
                    for (CLPlacemark *placemark in placemarks) {
                        NSLog(@"成功 %@",[placemark class]);
                        
                        NSLog(@"地理名称%@",placemark.name);
                        NSLog(@"街道名%@",placemark.thoroughfare);
                        NSLog(@"国家%@",placemark.country);
                        NSLog(@"城市%@",placemark.locality);
                        NSLog(@"区: %@",placemark.subLocality);
                        
                        NSLog(@"地址%@",placemark.addressDictionary);
                        NSLog(@"=======\n");
                    }
                }else{
                    NSLog(@"%@",error);
                }
                
            }];
        }



        @end

相关文章

  • 苹果地图 地理编码 反地理编码

    CoreLocation.framework 要用到这个框架 import

  • CLGeocoder

    CLGeocoder(地理编码) 使用CLGeocoder可以完成“地理编码”和“反地理编码”地理编码:根据给定的...

  • 地理编码

    地理编码和反地理编码都使用CLGeocoder类来实现. 地理编码使用 geocodeAddressString:...

  • 地图和定位(三)

    一、地理编码和反地理编码 地理编码:把地址转为经纬度反地理编码:把经纬度转为地址 二、获取当前城市名称(定位+反地...

  • 高德地图问题

    1:定位的时候获取用户的省市区位置,通过反地理编码 地理编码与反地理编码 地理编码:根据地址获得相应的经纬度以及详...

  • iOS开发之CoreLocaiton框架使用(地理编码,反地理编

    什么是地理编码和反地理编码? 地理编码 地理编码:根据给定的地名,获得具体的位置信息(比如经纬度、地址的全称等)。...

  • MapView演练

    结合MapView与LBS相关知识点:定位、地理编码/反地理编码、地图覆盖物、导航写了一个小的Demo 并且在导航...

  • 地理编码与反地理编码

    使用CLGeocoder可以完成“地理编码”和“反地理编码” 地理编码:根据给定的地名,获得具体的位置信息(比如经...

  • iOS 地理编码 / 反地理编码

    一、CLGeocoder 地理编码 与 反地理编码 地理编码:根据给定的地名,获得具体的位置信息(比如经纬度、地址...

  • 地理编码与反编码

    首先我们要了解地理编码和反编码的含义和作用:<1>地理编码:把地名转换成位置信息作用:把文字描述的 位置转换成地图...

网友评论

      本文标题:苹果地图 地理编码 反地理编码

      本文链接:https://www.haomeiwen.com/subject/phfdqttx.html