第一次提交
This commit is contained in:
1
location/.gitignore
vendored
Normal file
1
location/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
45
location/build.gradle
Normal file
45
location/build.gradle
Normal file
@@ -0,0 +1,45 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||
|
||||
ndk {
|
||||
abiFilters "armeabi", "armabi-v7a"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.0.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
|
||||
api 'com.amap.api:3dmap:9.1.0'
|
||||
//定位功能
|
||||
api 'com.amap.api:location:6.0.0'
|
||||
//搜索功能
|
||||
api 'com.amap.api:search:latest.integration'
|
||||
//implementation 'com.amap.api:location:latest.integration'
|
||||
implementation group: 'io.reactivex.rxjava2', name: 'rxandroid', version: '2.0.2'
|
||||
implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.1.12'
|
||||
}
|
||||
21
location/proguard-rules.pro
vendored
Normal file
21
location/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.fengliyan.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() throws Exception {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("com.caivideo.location.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
10
location/src/main/AndroidManifest.xml
Normal file
10
location/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.fengliyan.location" >
|
||||
<application android:allowBackup="true" android:label="@string/app_name"
|
||||
android:supportsRtl="true">
|
||||
<service android:name="com.amap.api.location.APSService"></service>
|
||||
<meta-data android:name="com.amap.api.v2.apikey"
|
||||
android:value="c28ae1af5ce3c5f69254e21aea21affb">
|
||||
</meta-data>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.fengliyan.location;
|
||||
|
||||
/**
|
||||
* Created by abby on 2018/4/7.
|
||||
*/
|
||||
|
||||
public class LocationBean {
|
||||
private String city;
|
||||
private String cityName;
|
||||
private String province;
|
||||
private String cityCode;
|
||||
private double longitude;
|
||||
private double latitude;
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCityName() {
|
||||
return cityName;
|
||||
}
|
||||
|
||||
public void setCityName(String cityName) {
|
||||
this.cityName = cityName;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCityCode() {
|
||||
return cityCode;
|
||||
}
|
||||
|
||||
public void setCityCode(String cityCode) {
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.fengliyan.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by abby on 2018/3/22.
|
||||
*/
|
||||
|
||||
public class LocationManager {
|
||||
private static LocationManager mInstance;
|
||||
private AMapLocationClient mLocationClient;
|
||||
private List<ObservableEmitter<LocationBean>> mEmitterList = new ArrayList<>();
|
||||
private Observable<LocationBean> mObservable;
|
||||
|
||||
public static LocationManager getInstance() {
|
||||
if (null == mInstance) {
|
||||
mInstance = new LocationManager();
|
||||
}
|
||||
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
private LocationManager() {
|
||||
mObservable = Observable.create(new ObservableOnSubscribe<LocationBean>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<LocationBean> emitter) throws Exception {
|
||||
mEmitterList.add(emitter);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
try {
|
||||
mLocationClient = new AMapLocationClient(context);
|
||||
mLocationClient.setLocationListener(new AMapLocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(AMapLocation aMapLocation) {
|
||||
|
||||
Log.e("AmapError", "location Error, ErrCode:"
|
||||
+ aMapLocation.getErrorCode() + ", errInfo:"
|
||||
+ aMapLocation.getErrorInfo());
|
||||
|
||||
String city = aMapLocation.getCity().replace("市", "");
|
||||
String province = aMapLocation.getProvince();
|
||||
String cityCode = aMapLocation.getCityCode();
|
||||
double longitude = aMapLocation.getLongitude();
|
||||
double latitude = aMapLocation.getLatitude();
|
||||
LocationBean locationBean = new LocationBean();
|
||||
locationBean.setCity(city);
|
||||
locationBean.setCityName(aMapLocation.getCity());
|
||||
locationBean.setProvince(province);
|
||||
locationBean.setCityCode(cityCode);
|
||||
locationBean.setLatitude(latitude);
|
||||
locationBean.setLongitude(longitude);
|
||||
|
||||
|
||||
Iterator<ObservableEmitter<LocationBean>> i = mEmitterList.iterator();
|
||||
while (i.hasNext()) {
|
||||
ObservableEmitter<LocationBean> emitter = i.next();
|
||||
emitter.onNext(locationBean);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (null != mLocationClient) {
|
||||
mLocationClient.stopLocation();
|
||||
mLocationClient.startLocation();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (null != mLocationClient) {
|
||||
mLocationClient.stopLocation();
|
||||
}
|
||||
}
|
||||
|
||||
public void addLocationObserver(Observer<LocationBean> observer) {
|
||||
mObservable.subscribe(observer);
|
||||
}
|
||||
|
||||
}
|
||||
3
location/src/main/res/values/strings.xml
Normal file
3
location/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Location</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.fengliyan.location;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user