Git Product home page Git Product logo

amaplocation's Introduction

AMapLocation

高德定位基础library类

1.引入

dependencies {
    compile project(':AMapLocation')
}

或者使用aar依赖方式(当然需要自己生成aar包),直接将.aar包放入libs文件夹,并且

android {  
    ... 
    repositories {  
        flatDir {  
        dirs 'libs'  
    }  
}
dependencies {  
    ...
    compile(name:'这里aar包文件名', ext:'aar')  
}  

或者直接将.arr包放入libs文件夹

2.配置

先在 AndroidManifest.xml 中添加

<application
    ...
    >
    
    <meta-data
        android:name="com.amap.api.v2.apikey"
        android:value="${amapKey}" />

</application>

然后再

buildTypes {
    release {
        ...
        manifestPlaceholders = [
                amapKey: "这里放key"
        ]
    }
    debug {
        ...
        manifestPlaceholders = [
                amapKey: "这里放key"
        ]
    }
}

3.使用

private void startLocation() {
    AMapLocationService locationService = new AMapLocationService(this);
    locationService.setLocationOption(locationService.getDefaultLocationOption());
    locationService.addLocationListener(new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
            //do something
        }
    });
    locationService.startLocation();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    locationService.stopLocation();  
    locationService.destroyLocationClient();
}

注意

  • Android 6.0 + 需要动态请求位置权限
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE

amaplocation's People

Contributors

wuxiaosu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

netstu

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.