Giter VIP home page Giter VIP logo

dnlocationmanager's Introduction

DNLocationManager

定位功能封装 ###功能介绍 本项目主要是对常用的定位功能的一次封装,通过block回调的方式返回坐标、所在位置的具体地址、所在城市名称,使用起来也比较方便实用。

###开启定位功能需要的配置 1.添加依赖库CoreLocation.framework

2.配置plist文件添加两个字段(注意:类型要选择String,ios8中类型选择boolean会出现设置界面崩溃的情况)

NSLocationAlwaysUsageDescription String YES

NSLocationWhenInUseUsageDescription String YES

#使用说明 1.引入头文件#import "DNLocationManager.h"

2.调用相应的方法获取对应信息

获取坐标

- (void)getLocation {
    [[DNLocationManager shareLocation] getLocationCoordinate:^(CLLocationCoordinate2D locationCorrrdinate) {
       NSLog(@"经度:%f  纬度:%f",locationCorrrdinate.latitude, locationCorrrdinate.longitude);
   } failure:^(NSError *error) {
       NSLog(@"获取坐标失败:%@",error);
    }];
}

获取地址

- (void)getAddress {
    [[DNLocationManager shareLocation] getAddress:^(NSString *addressString) {
        NSLog(@"获取到的地址:%@",addressString);
    } failure:^(NSError *error) {
        NSLog(@"获取地址失败:%@",error);
    }];
}

获取坐标和地址

- (void)getLocationAndAddress {
   [[DNLocationManager shareLocation] getLocationCoordinate:^(CLLocationCoordinate2D locationCorrrdinate) {
        NSLog(@"经度:%f  纬度:%f",locationCorrrdinate.latitude, locationCorrrdinate.longitude);
    } withAddress:^(NSString *addressString) {
        NSLog(@"获取到的地址:%@",addressString);
   } failure:^(NSError *error) {
        NSLog(@"获取坐标失败:%@",error);
    } addressFailure:^(NSError *error) {
        NSLog(@"获取地址失败:%@",error);
    }];
}

获取城市

- (void)getCity {
    [[DNLocationManager shareLocation] getCity:^(NSString *cityString) {
        NSLog(@"城市名称:%@",cityString);
    } failure:^(NSError *error) {
        NSLog(@"获取城市失败:%@",error);
    }];
}

dnlocationmanager's People

Contributors

626600815 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.