├── .gitignore
├── LICENSE
├── README.md
├── android_studio
├── AMapLocationDemo
│ ├── .gitignore
│ ├── .idea
│ │ ├── .name
│ │ ├── compiler.xml
│ │ ├── copyright
│ │ │ └── profiles_settings.xml
│ │ ├── dictionaries
│ │ │ └── hongming_wang.xml
│ │ ├── encodings.xml
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ ├── Project_Default.xml
│ │ │ └── profiles_settings.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── runConfigurations.xml
│ ├── app
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── libs
│ │ │ ├── AMap_Location_V3.3.0_20170118.jar
│ │ │ ├── Android_Map3D_SDK_V4.1.2_20161104.jar
│ │ │ ├── android-support-v4.jar
│ │ │ └── armeabi
│ │ │ │ ├── libgdinamapv4sdk752.so
│ │ │ │ └── libgdinamapv4sdk752ex.so
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── amap
│ │ │ │ │ └── location
│ │ │ │ │ └── demo
│ │ │ │ │ ├── Alarm_Location_Activity.java
│ │ │ │ │ ├── Assistant_Location_Activity.java
│ │ │ │ │ ├── CheckPermissionsActivity.java
│ │ │ │ │ ├── Const.java
│ │ │ │ │ ├── ErrorCode_Activity.java
│ │ │ │ │ ├── GeoFence_Activity.java
│ │ │ │ │ ├── GeoFence_District_Activity.java
│ │ │ │ │ ├── GeoFence_Keyword_Activity.java
│ │ │ │ │ ├── GeoFence_Multiple_Activity.java
│ │ │ │ │ ├── GeoFence_Nearby_Activity.java
│ │ │ │ │ ├── GeoFence_Old_Activity.java
│ │ │ │ │ ├── GeoFence_Polygon_Activity.java
│ │ │ │ │ ├── GeoFence_Round_Activity.java
│ │ │ │ │ ├── LastLocation_Activity.java
│ │ │ │ │ ├── Location_Activity.java
│ │ │ │ │ ├── StartActivity.java
│ │ │ │ │ ├── Tools_Activity.java
│ │ │ │ │ ├── Utils.java
│ │ │ │ │ └── view
│ │ │ │ │ └── FeatureView.java
│ │ │ └── res
│ │ │ │ ├── drawable-hdpi
│ │ │ │ ├── gps_point.png
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── drawable-ldpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── layout
│ │ │ │ ├── activity_alarm_location.xml
│ │ │ │ ├── activity_assistant_location.xml
│ │ │ │ ├── activity_errcode.xml
│ │ │ │ ├── activity_geofence.xml
│ │ │ │ ├── activity_geofence_new.xml
│ │ │ │ ├── activity_geofence_old.xml
│ │ │ │ ├── activity_lastlocation.xml
│ │ │ │ ├── activity_location.xml
│ │ │ │ ├── activity_start.xml
│ │ │ │ ├── activity_tools.xml
│ │ │ │ ├── feature.xml
│ │ │ │ ├── plugin_geofence_map.xml
│ │ │ │ ├── plugin_geofence_option.xml
│ │ │ │ └── plugin_location_option.xml
│ │ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── strings.xml
│ │ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── amap
│ │ │ └── location
│ │ │ └── demo
│ │ │ └── ExampleUnitTest.java
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
└── Readme.md
└── eclipse
├── AMapLocationDemo
├── .classpath
├── .gitignore
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ └── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── assets
│ └── location.html
├── ic_launcher-web.png
├── libs
│ ├── AMap_Location_V3.3.0_20170118.jar
│ ├── Android_Map3D_SDK_V4.1.2_20161104.jar
│ ├── android-support-v4.jar
│ └── armeabi
│ │ ├── libgdinamapv4sdk752.so
│ │ └── libgdinamapv4sdk752ex.so
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ ├── gps_point.png
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── activity_alarm_location.xml
│ │ ├── activity_assistant_location.xml
│ │ ├── activity_errcode.xml
│ │ ├── activity_geofence.xml
│ │ ├── activity_geofence_new.xml
│ │ ├── activity_geofence_old.xml
│ │ ├── activity_lastlocation.xml
│ │ ├── activity_location.xml
│ │ ├── activity_start.xml
│ │ ├── activity_tools.xml
│ │ ├── feature.xml
│ │ ├── plugin_geofence_map.xml
│ │ ├── plugin_geofence_option.xml
│ │ └── plugin_location_option.xml
│ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ └── strings.xml
└── src
│ └── com
│ └── amap
│ └── location
│ └── demo
│ ├── Alarm_Location_Activity.java
│ ├── Assistant_Location_Activity.java
│ ├── CheckPermissionsActivity.java
│ ├── Const.java
│ ├── ErrorCode_Activity.java
│ ├── GeoFence_Activity.java
│ ├── GeoFence_District_Activity.java
│ ├── GeoFence_Keyword_Activity.java
│ ├── GeoFence_Multiple_Activity.java
│ ├── GeoFence_Nearby_Activity.java
│ ├── GeoFence_Old_Activity.java
│ ├── GeoFence_Polygon_Activity.java
│ ├── GeoFence_Round_Activity.java
│ ├── LastLocation_Activity.java
│ ├── Location_Activity.java
│ ├── StartActivity.java
│ ├── Tools_Activity.java
│ ├── Utils.java
│ └── view
│ └── FeatureView.java
└── Readme.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android_Location_Demo
2 | 高德定位SDK示例
3 | ------------
4 |
5 | 本工程为高德定位Android SDK官方Demo
6 |
7 | ##前述:
8 | - [高德官方网站申请key](http://lbs.amap.com/dev/#/).
9 | - 阅读[参考手册](http://amappc.cn-hangzhou.oss-pub.aliyun-inc.com/lbs/static/unzip/Android_Location_Doc/index.html).
10 | - 如果有任何疑问也可以发问题到[官方论坛](http://lbsbbs.amap.com/forum.php?mod=forumdisplay&fid=48).
11 |
12 | ##包含的功能点
13 | - 获取定位数据.
14 | - 地理围栏
15 | - H5辅助定位
16 | - 地图计算工具
17 | - 获取最后一次位置
18 | - 定时唤起CPU
19 | - 错误码说明
20 |
21 | ##使用方法:
22 | [使用方法](http://lbs.amap.com/api/android-location-sdk/locationsummary/)
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/.name:
--------------------------------------------------------------------------------
1 | AMapLocationDemo
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/dictionaries/hongming_wang.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /*.apk
3 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | sourceSets {
5 | main {
6 | jniLibs.srcDirs = ['libs']
7 | }
8 | }
9 | signingConfigs {
10 | /**
11 | * 设置你的keystore相关
12 | * demo中只是一个示例,使用时请根据实际情况进行配置
13 | */
14 | // debug {
15 | // //keystore中key的别名
16 | // keyAlias 'androiddebugkey'
17 | // //keystore中key的密码
18 | // keyPassword 'android'
19 | // //keystore的文件路径,可以是绝对路径也可以是相对路径
20 | // storeFile file('D:/keystore/debug_loc.keystore')
21 | // //keystore的密码
22 | // storePassword 'android'
23 | // }
24 | }
25 | compileSdkVersion 23
26 | buildToolsVersion '23.0.1'
27 |
28 | defaultConfig {
29 | applicationId "com.amap.location.demo"
30 | minSdkVersion 14
31 | targetSdkVersion 22
32 | versionCode 2
33 | versionName "2.0"
34 | }
35 | buildTypes {
36 | release {
37 | minifyEnabled false
38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39 | }
40 | }
41 | }
42 |
43 | dependencies {
44 | compile fileTree(include: ['*.jar'], dir: 'libs')
45 | }
46 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/libs/AMap_Location_V3.3.0_20170118.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/libs/AMap_Location_V3.3.0_20170118.jar
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/libs/Android_Map3D_SDK_V4.1.2_20161104.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/libs/Android_Map3D_SDK_V4.1.2_20161104.jar
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/libs/armeabi/libgdinamapv4sdk752.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/libs/armeabi/libgdinamapv4sdk752.so
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/libs/armeabi/libgdinamapv4sdk752ex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/libs/armeabi/libgdinamapv4sdk752ex.so
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
55 |
56 |
59 |
60 |
61 |
62 |
63 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
79 |
80 |
85 |
86 |
91 |
92 |
97 |
98 |
103 |
104 |
109 |
110 |
115 |
116 |
121 |
122 |
127 |
128 |
133 |
134 |
139 |
140 |
145 |
146 |
151 |
152 |
157 |
158 |
159 |
160 |
161 |
162 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/Alarm_Location_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.location.AMapLocation;
4 | import com.amap.api.location.AMapLocationClient;
5 | import com.amap.api.location.AMapLocationClientOption;
6 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode;
7 | import com.amap.api.location.AMapLocationListener;
8 |
9 | import android.app.Activity;
10 | import android.app.AlarmManager;
11 | import android.app.PendingIntent;
12 | import android.content.BroadcastReceiver;
13 | import android.content.Context;
14 | import android.content.Intent;
15 | import android.content.IntentFilter;
16 | import android.os.Bundle;
17 | import android.os.Handler;
18 | import android.os.Message;
19 | import android.os.SystemClock;
20 | import android.text.TextUtils;
21 | import android.view.View;
22 | import android.view.View.OnClickListener;
23 | import android.widget.Button;
24 | import android.widget.CheckBox;
25 | import android.widget.EditText;
26 | import android.widget.TextView;
27 | import android.widget.Toast;
28 |
29 | /**
30 | * 后台唤醒定位
31 | * @创建时间:2016年1月8日 上午11:25:01
32 | * @项目名称: AMapLocationDemo2.x
33 | * @author hongming.wang
34 | * @文件名称:Alarm_Location_Activity.java
35 | * @类型名称:Alarm_Location_Activity
36 | * @since 2.3.0
37 | */
38 | public class Alarm_Location_Activity extends CheckPermissionsActivity implements
39 | OnClickListener, AMapLocationListener {
40 | private EditText etInterval;
41 | private EditText etAlarm;
42 | private CheckBox cbAddress;
43 | private CheckBox cbGpsFirst;
44 | private TextView tvReult;
45 | private Button btLocation;
46 |
47 | private AMapLocationClient locationClient = null;
48 | private AMapLocationClientOption locationOption = null;
49 |
50 | private Intent alarmIntent = null;
51 | private PendingIntent alarmPi = null;
52 | private AlarmManager alarm = null;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.activity_alarm_location);
58 | setTitle(R.string.title_alarmCPU);
59 |
60 | etInterval = (EditText) findViewById(R.id.et_interval);
61 | etAlarm = (EditText) findViewById(R.id.et_alarm);
62 | cbAddress = (CheckBox) findViewById(R.id.cb_needAddress);
63 | cbGpsFirst = (CheckBox) findViewById(R.id.cb_gpsFirst);
64 | tvReult = (TextView) findViewById(R.id.tv_result);
65 | btLocation = (Button) findViewById(R.id.bt_location);
66 |
67 | btLocation.setOnClickListener(this);
68 |
69 | locationClient = new AMapLocationClient(this.getApplicationContext());
70 | locationOption = new AMapLocationClientOption();
71 | // 设置定位模式为高精度模式
72 | locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
73 | // 设置定位监听
74 | locationClient.setLocationListener(this);
75 |
76 | // 创建Intent对象,action为LOCATION
77 | alarmIntent = new Intent();
78 | alarmIntent.setAction("LOCATION");
79 | IntentFilter ift = new IntentFilter();
80 |
81 | // 定义一个PendingIntent对象,PendingIntent.getBroadcast包含了sendBroadcast的动作。
82 | // 也就是发送了action 为"LOCATION"的intent
83 | alarmPi = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
84 | // AlarmManager对象,注意这里并不是new一个对象,Alarmmanager为系统级服务
85 | alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
86 |
87 | //动态注册一个广播
88 | IntentFilter filter = new IntentFilter();
89 | filter.addAction("LOCATION");
90 | registerReceiver(alarmReceiver, filter);
91 | }
92 |
93 | @Override
94 | protected void onDestroy() {
95 | super.onDestroy();
96 | if (null != locationClient) {
97 | /**
98 | * 如果AMapLocationClient是在当前Activity实例化的,
99 | * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
100 | */
101 | locationClient.onDestroy();
102 | locationClient = null;
103 | locationOption = null;
104 | }
105 |
106 | if(null != alarmReceiver){
107 | unregisterReceiver(alarmReceiver);
108 | alarmReceiver = null;
109 | }
110 | }
111 |
112 | /**
113 | * 设置控件的可用状态
114 | */
115 | private void setViewEnable(boolean isEnable) {
116 | etInterval.setEnabled(isEnable);
117 | etAlarm.setEnabled(isEnable);
118 | cbAddress.setEnabled(isEnable);
119 | cbGpsFirst.setEnabled(isEnable);
120 | }
121 |
122 | @Override
123 | public void onClick(View v) {
124 | if (v.getId() == R.id.bt_location) {
125 | if (btLocation.getText().equals(
126 | getResources().getString(R.string.startLocation))) {
127 | setViewEnable(false);
128 | initOption();
129 | int alarmInterval = 5;
130 | String str = etAlarm.getText().toString();
131 | if(!TextUtils.isEmpty(str)){
132 | alarmInterval = Integer.parseInt(str);
133 | }
134 |
135 | btLocation.setText(getResources().getString(
136 | R.string.stopLocation));
137 | // 设置定位参数
138 | locationClient.setLocationOption(locationOption);
139 | // 启动定位
140 | locationClient.startLocation();
141 | mHandler.sendEmptyMessage(Utils.MSG_LOCATION_START);
142 |
143 | if(null != alarm){
144 | //设置一个闹钟,2秒之后每隔一段时间执行启动一次定位程序
145 | alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 2*1000,
146 | alarmInterval * 1000, alarmPi);
147 | }
148 | } else {
149 | setViewEnable(true);
150 | btLocation.setText(getResources().getString(
151 | R.string.startLocation));
152 | // 停止定位
153 | locationClient.stopLocation();
154 | mHandler.sendEmptyMessage(Utils.MSG_LOCATION_STOP);
155 |
156 | //停止定位的时候取消闹钟
157 | if(null != alarm){
158 | alarm.cancel(alarmPi);
159 | }
160 | }
161 | }
162 | }
163 |
164 | // 根据控件的选择,重新设置定位参数
165 | private void initOption() {
166 | // 设置是否需要显示地址信息
167 | locationOption.setNeedAddress(cbAddress.isChecked());
168 | /**
169 | * 设置是否优先返回GPS定位结果,如果30秒内GPS没有返回定位结果则进行网络定位
170 | * 注意:只有在高精度模式下的单次定位有效,其他方式无效
171 | */
172 | locationOption.setGpsFirst(cbGpsFirst.isChecked());
173 | String strInterval = etInterval.getText().toString();
174 | if (!TextUtils.isEmpty(strInterval)) {
175 | // 设置发送定位请求的时间间隔,最小值为1000,如果小于1000,按照1000算
176 | locationOption.setInterval(Long.valueOf(strInterval));
177 | }
178 |
179 | }
180 |
181 | Handler mHandler = new Handler() {
182 | public void dispatchMessage(android.os.Message msg) {
183 | switch (msg.what) {
184 | //开始定位
185 | case Utils.MSG_LOCATION_START:
186 | tvReult.setText("正在定位...");
187 | break;
188 | // 定位完成
189 | case Utils.MSG_LOCATION_FINISH:
190 | AMapLocation loc = (AMapLocation) msg.obj;
191 | String result = Utils.getLocationStr(loc);
192 | tvReult.setText(result);
193 | break;
194 | //停止定位
195 | case Utils.MSG_LOCATION_STOP:
196 | tvReult.setText("定位停止");
197 | break;
198 | default:
199 | break;
200 | }
201 | };
202 | };
203 |
204 | // 定位监听
205 | @Override
206 | public void onLocationChanged(AMapLocation loc) {
207 | if (null != loc) {
208 | Message msg = mHandler.obtainMessage();
209 | msg.obj = loc;
210 | msg.what = Utils.MSG_LOCATION_FINISH;
211 | mHandler.sendMessage(msg);
212 | }
213 | }
214 |
215 |
216 | private BroadcastReceiver alarmReceiver = new BroadcastReceiver(){
217 | @Override
218 | public void onReceive(Context context, Intent intent) {
219 | if(intent.getAction().equals("LOCATION")){
220 | if(null != locationClient){
221 | locationClient.startLocation();
222 | }
223 | }
224 | }
225 | };
226 |
227 | }
228 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/Assistant_Location_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.location.AMapLocationClient;
4 |
5 | import android.app.Activity;
6 | import android.graphics.Bitmap;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.view.View.OnClickListener;
10 | import android.view.Window;
11 | import android.webkit.GeolocationPermissions.Callback;
12 | import android.webkit.JsResult;
13 | import android.webkit.WebChromeClient;
14 | import android.webkit.WebSettings;
15 | import android.webkit.WebView;
16 | import android.webkit.WebViewClient;
17 | import android.widget.Button;
18 |
19 | /**
20 | * H5辅助定位模式功能演示
21 | *
22 | * @创建时间: 2015年11月24日 下午4:24:07
23 | * @项目名称: AMapLocationDemo2.x
24 | *
25 | * @author hongming.wang
26 | * @文件名称: Battery_Saving_Activity.java
27 | * @类型名称: Battery_Saving_Activity
28 | */
29 | public class Assistant_Location_Activity extends CheckPermissionsActivity implements OnClickListener {
30 | private Button btAssistant;
31 | private Button btLocation;
32 |
33 | private AMapLocationClient locationClient = null;
34 |
35 | private WebView webView;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_assistant_location);
41 | setTitle(R.string.title_assistantLocation);
42 |
43 | btAssistant = (Button) findViewById(R.id.bt_assistant);
44 | btLocation = (Button) findViewById(R.id.bt_location);
45 |
46 | locationClient = new AMapLocationClient(getApplicationContext());
47 | btAssistant.setOnClickListener(this);
48 | btLocation.setOnClickListener(this);
49 |
50 | initWebView();
51 | }
52 |
53 | private void initWebView(){
54 | webView = (WebView) findViewById(R.id.webView);
55 |
56 | WebSettings webSettings = webView.getSettings();
57 | // 允许webview执行javaScript脚本
58 | webSettings.setJavaScriptEnabled(true);
59 | // 设置是否允许定位,这里为了使用H5辅助定位,设置为false。
60 | //设置为true不一定会进行H5辅助定位,设置为true时只有H5定位失败后才会进行辅助定位
61 | webSettings.setGeolocationEnabled(false);
62 |
63 |
64 | webView.setWebViewClient(new WebViewClient() {
65 |
66 | public void onPageFinished(WebView view, String url) {
67 | super.onPageFinished(view, url);
68 | }
69 |
70 | public void onPageStarted(WebView view, String url, Bitmap favicon) {
71 | super.onPageStarted(view, url, favicon);
72 | }
73 | });
74 |
75 | webView.setWebChromeClient(new WebChromeClient() {
76 | // 处理javascript中的alert
77 | public boolean onJsAlert(WebView view, String url, String message,
78 | final JsResult result) {
79 | return true;
80 | };
81 |
82 | // 处理javascript中的confirm
83 | public boolean onJsConfirm(WebView view, String url,
84 | String message, final JsResult result) {
85 | return true;
86 | };
87 |
88 | // 处理定位权限请求
89 | @Override
90 | public void onGeolocationPermissionsShowPrompt(String origin,
91 | Callback callback) {
92 | callback.invoke(origin, true, false);
93 | super.onGeolocationPermissionsShowPrompt(origin, callback);
94 | }
95 | @Override
96 | // 设置网页加载的进度条
97 | public void onProgressChanged(WebView view, int newProgress) {
98 | Assistant_Location_Activity.this.getWindow().setFeatureInt(
99 | Window.FEATURE_PROGRESS, newProgress * 100);
100 | super.onProgressChanged(view, newProgress);
101 | }
102 |
103 | // 设置应用程序的标题title
104 | public void onReceivedTitle(WebView view, String title) {
105 | super.onReceivedTitle(view, title);
106 | }
107 | });
108 | }
109 |
110 | @Override
111 | protected void onDestroy() {
112 | super.onDestroy();
113 | if (null != locationClient) {
114 | locationClient.stopAssistantLocation();
115 | locationClient.onDestroy();
116 | }
117 | if(null != webView){
118 | webView.destroy();
119 | }
120 | }
121 |
122 | @Override
123 | public void onClick(View v) {
124 | if (v.getId() == R.id.bt_assistant) {
125 | if (btAssistant.getText().equals(getResources().getString(R.string.startAssistantLocation))) {
126 | btAssistant.setText(getResources().getString(R.string.stopAssistantLocation));
127 | locationClient.startAssistantLocation();
128 | btLocation.setEnabled(true);
129 | } else {
130 | btAssistant.setText(getResources().getString(R.string.startAssistantLocation));
131 | locationClient.stopAssistantLocation();
132 | btLocation.setEnabled(false);
133 | webView.setVisibility(View.GONE);
134 | }
135 | } else if (v.getId() == R.id.bt_location) {
136 | webView.setVisibility(View.VISIBLE);
137 | //浏览器定位,加载预置的H5定位页面
138 | webView.loadUrl(Utils.URL_H5LOCATION);
139 | }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/CheckPermissionsActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import android.Manifest;
10 | import android.app.Activity;
11 | import android.app.AlertDialog;
12 | import android.content.DialogInterface;
13 | import android.content.Intent;
14 | import android.content.pm.PackageManager;
15 | import android.net.Uri;
16 | import android.provider.Settings;
17 | import android.support.v4.app.ActivityCompat;
18 | import android.support.v4.content.ContextCompat;
19 | import android.view.KeyEvent;
20 |
21 | /**
22 | * 继承了Activity,实现Android6.0的运行时权限检测
23 | * 需要进行运行时权限检测的Activity可以继承这个类
24 | *
25 | * @创建时间:2016年5月27日 下午3:01:31
26 | * @项目名称: AMapLocationDemo
27 | * @author hongming.wang
28 | * @文件名称:PermissionsChecker.java
29 | * @类型名称:PermissionsChecker
30 | * @since 2.5.0
31 | */
32 | public class CheckPermissionsActivity extends Activity
33 | implements
34 | ActivityCompat.OnRequestPermissionsResultCallback {
35 | /**
36 | * 需要进行检测的权限数组
37 | */
38 | protected String[] needPermissions = {
39 | Manifest.permission.ACCESS_COARSE_LOCATION,
40 | Manifest.permission.ACCESS_FINE_LOCATION,
41 | Manifest.permission.WRITE_EXTERNAL_STORAGE,
42 | Manifest.permission.READ_EXTERNAL_STORAGE,
43 | Manifest.permission.READ_PHONE_STATE
44 | };
45 |
46 | private static final int PERMISSON_REQUESTCODE = 0;
47 |
48 | /**
49 | * 判断是否需要检测,防止不停的弹框
50 | */
51 | private boolean isNeedCheck = true;
52 |
53 | @Override
54 | protected void onResume() {
55 | super.onResume();
56 | if(isNeedCheck){
57 | checkPermissions(needPermissions);
58 | }
59 | }
60 |
61 | /**
62 | *
63 | * @param needRequestPermissonList
64 | * @since 2.5.0
65 | *
66 | */
67 | private void checkPermissions(String... permissions) {
68 | List needRequestPermissonList = findDeniedPermissions(permissions);
69 | if (null != needRequestPermissonList
70 | && needRequestPermissonList.size() > 0) {
71 | ActivityCompat.requestPermissions(this,
72 | needRequestPermissonList.toArray(
73 | new String[needRequestPermissonList.size()]),
74 | PERMISSON_REQUESTCODE);
75 | }
76 | }
77 |
78 | /**
79 | * 获取权限集中需要申请权限的列表
80 | *
81 | * @param permissions
82 | * @return
83 | * @since 2.5.0
84 | *
85 | */
86 | private List findDeniedPermissions(String[] permissions) {
87 | List needRequestPermissonList = new ArrayList();
88 | for (String perm : permissions) {
89 | if (ContextCompat.checkSelfPermission(this,
90 | perm) != PackageManager.PERMISSION_GRANTED
91 | || ActivityCompat.shouldShowRequestPermissionRationale(
92 | this, perm)) {
93 | needRequestPermissonList.add(perm);
94 | }
95 | }
96 | return needRequestPermissonList;
97 | }
98 |
99 | /**
100 | * 检测是否说有的权限都已经授权
101 | * @param grantResults
102 | * @return
103 | * @since 2.5.0
104 | *
105 | */
106 | private boolean verifyPermissions(int[] grantResults) {
107 | for (int result : grantResults) {
108 | if (result != PackageManager.PERMISSION_GRANTED) {
109 | return false;
110 | }
111 | }
112 | return true;
113 | }
114 |
115 | @Override
116 | public void onRequestPermissionsResult(int requestCode,
117 | String[] permissions, int[] paramArrayOfInt) {
118 | if (requestCode == PERMISSON_REQUESTCODE) {
119 | if (!verifyPermissions(paramArrayOfInt)) {
120 | showMissingPermissionDialog();
121 | isNeedCheck = false;
122 | }
123 | }
124 | }
125 |
126 | /**
127 | * 显示提示信息
128 | *
129 | * @since 2.5.0
130 | *
131 | */
132 | private void showMissingPermissionDialog() {
133 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
134 | builder.setTitle(R.string.notifyTitle);
135 | builder.setMessage(R.string.notifyMsg);
136 |
137 | // 拒绝, 退出应用
138 | builder.setNegativeButton(R.string.cancel,
139 | new DialogInterface.OnClickListener() {
140 | @Override
141 | public void onClick(DialogInterface dialog, int which) {
142 | finish();
143 | }
144 | });
145 |
146 | builder.setPositiveButton(R.string.setting,
147 | new DialogInterface.OnClickListener() {
148 | @Override
149 | public void onClick(DialogInterface dialog, int which) {
150 | startAppSettings();
151 | }
152 | });
153 |
154 | builder.setCancelable(false);
155 |
156 | builder.show();
157 | }
158 |
159 | /**
160 | * 启动应用的设置
161 | *
162 | * @since 2.5.0
163 | *
164 | */
165 | private void startAppSettings() {
166 | Intent intent = new Intent(
167 | Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
168 | intent.setData(Uri.parse("package:" + getPackageName()));
169 | startActivity(intent);
170 | }
171 |
172 | @Override
173 | public boolean onKeyDown(int keyCode, KeyEvent event) {
174 | if(keyCode == KeyEvent.KEYCODE_BACK){
175 | this.finish();
176 | return true;
177 | }
178 | return super.onKeyDown(keyCode, event);
179 | }
180 |
181 | }
182 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/Const.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import android.graphics.Color;
4 |
5 | /**
6 | * @since 3.3.0
7 | * Created by hongming.wang on 2016/12/19.
8 | */
9 |
10 | public class Const {
11 | /**
12 | * 地图中绘制多边形、圆形的边界颜色
13 | * @since 3.3.0
14 | */
15 | public static final int STROKE_COLOR = Color.argb(180, 63, 145, 252);
16 | /**
17 | * 地图中绘制多边形、圆形的填充颜色
18 | * @since 3.3.0
19 | */
20 | public static final int FILL_COLOR = Color.argb(163, 118, 212, 243);
21 |
22 | /**
23 | * 地图中绘制多边形、圆形的边框宽度
24 | * @since 3.3.0
25 | */
26 | public static final float STROKE_WIDTH = 5F;
27 | }
28 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/ErrorCode_Activity.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 |
7 | import android.app.Activity;
8 | import android.os.Bundle;
9 | import android.view.KeyEvent;
10 | import android.widget.TextView;
11 |
12 | /**
13 | * 错误码说明
14 | * @创建时间:2016年5月31日 上午11:22:06
15 | * @项目名称: AMapLocationDemo
16 | * @author hongming.wang
17 | * @文件名称:ErrorCodeInfo.java
18 | * @类型名称:ErrorCodeInfo
19 | * @since 2.5.0
20 | */
21 | public class ErrorCode_Activity extends Activity{
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_errcode);
27 | setTitle(R.string.title_errorCode);
28 | }
29 |
30 | @Override
31 | public boolean onKeyDown(int keyCode, KeyEvent event) {
32 | if(keyCode == KeyEvent.KEYCODE_BACK){
33 | this.finish();
34 | return true;
35 | }
36 | return super.onKeyDown(keyCode, event);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/GeoFence_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.location.demo.view.FeatureView;
4 |
5 | import android.app.ListActivity;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.view.KeyEvent;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.ListAdapter;
14 | import android.widget.ListView;
15 |
16 | /**
17 | * 地理围栏功能演示
18 | *
19 | * @创建时间: 2015年11月24日 下午5:49:52
20 | * @项目名称: AMapLocationDemo2.x
21 | * @author hongming.wang
22 | * @文件名称: GeoFence_Activity.java
23 | * @类型名称: GeoFence_Activity
24 | */
25 | public class GeoFence_Activity extends ListActivity {
26 | private static class DemoDetails {
27 | private final int titleId;
28 | private final int descriptionId;
29 | private final Class extends android.app.Activity> activityClass;
30 | public DemoDetails(int titleId, int descriptionId,
31 | Class extends android.app.Activity> activityClass) {
32 | super();
33 | this.titleId = titleId;
34 | this.descriptionId = descriptionId;
35 | this.activityClass = activityClass;
36 | }
37 | }
38 |
39 | private static class CustomArrayAdapter extends ArrayAdapter {
40 | public CustomArrayAdapter(Context context, DemoDetails[] demos) {
41 | super(context, R.layout.feature, R.id.title, demos);
42 | }
43 |
44 | @Override
45 | public View getView(int position, View convertView, ViewGroup parent) {
46 | FeatureView featureView;
47 | if (convertView instanceof FeatureView) {
48 | featureView = (FeatureView) convertView;
49 | } else {
50 | featureView = new FeatureView(getContext());
51 | }
52 | DemoDetails demo = getItem(position);
53 | featureView.setTitleId(demo.titleId);
54 | featureView.setDescriptionId(demo.descriptionId);
55 | return featureView;
56 | }
57 | }
58 |
59 | private static final DemoDetails[] demos = {
60 | new DemoDetails(R.string.roundGeoFence,
61 | R.string.roundGeoFence_dec, GeoFence_Round_Activity.class),
62 | new DemoDetails(R.string.polygonGeoFence,
63 | R.string.polygonGeoFence_dec, GeoFence_Polygon_Activity.class),
64 | new DemoDetails(R.string.keywordGeoFence,
65 | R.string.keywordGeoFence_dec, GeoFence_Keyword_Activity.class),
66 | new DemoDetails(R.string.nearbyGeoFence,
67 | R.string.nearbyGeoFence_dec, GeoFence_Nearby_Activity.class),
68 | new DemoDetails(R.string.districtGeoFence,
69 | R.string.districtGeoFence_dec, GeoFence_District_Activity.class),
70 | new DemoDetails(R.string.multipleGeoFence, R.string.multipleGeoFence_dec,
71 | GeoFence_Multiple_Activity.class),
72 | new DemoDetails(R.string.oldGeoFence, R.string.oldGeoFence_dec,
73 | GeoFence_Old_Activity.class),
74 | };
75 |
76 | @Override
77 | protected void onCreate(Bundle savedInstanceState) {
78 | super.onCreate(savedInstanceState);
79 | setContentView(R.layout.activity_geofence);
80 | setTitle(R.string.title_main);
81 | ListAdapter adapter = new CustomArrayAdapter(
82 | this.getApplicationContext(), demos);
83 | setListAdapter(adapter);
84 | // permChecker = new PermissionsChecker(this);
85 | }
86 |
87 | @Override
88 | public void onBackPressed() {
89 | super.onBackPressed();
90 | System.exit(0);
91 | }
92 |
93 | @Override
94 | protected void onListItemClick(ListView l, View v, int position, long id) {
95 | DemoDetails demo = (DemoDetails) getListAdapter().getItem(position);
96 | startActivity(
97 | new Intent(this.getApplicationContext(), demo.activityClass));
98 | }
99 | @Override
100 | public boolean onKeyDown(int keyCode, KeyEvent event) {
101 | if(keyCode == KeyEvent.KEYCODE_BACK){
102 | this.finish();
103 | return true;
104 | }
105 | return super.onKeyDown(keyCode, event);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/GeoFence_Old_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.fence.GeoFence;
4 | import com.amap.api.location.AMapLocation;
5 | import com.amap.api.location.AMapLocationClient;
6 | import com.amap.api.location.AMapLocationClientOption;
7 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode;
8 | import com.amap.api.location.AMapLocationListener;
9 |
10 | import android.app.PendingIntent;
11 | import android.content.BroadcastReceiver;
12 | import android.content.Context;
13 | import android.content.Intent;
14 | import android.content.IntentFilter;
15 | import android.net.ConnectivityManager;
16 | import android.os.Bundle;
17 | import android.os.Handler;
18 | import android.os.Message;
19 | import android.text.TextUtils;
20 | import android.view.View;
21 | import android.view.View.OnClickListener;
22 | import android.widget.Button;
23 | import android.widget.CheckBox;
24 | import android.widget.EditText;
25 | import android.widget.TextView;
26 | import android.widget.Toast;
27 |
28 | /**
29 | * 地理围栏功能演示
30 | *
31 | * @创建时间: 2015年11月24日 下午5:49:52
32 | * @项目名称: AMapLocationDemo2.x
33 | * @author hongming.wang
34 | * @文件名称: GeoFence_Activity.java
35 | * @类型名称: GeoFence_Activity
36 | */
37 | public class GeoFence_Old_Activity extends CheckPermissionsActivity implements OnClickListener,
38 | AMapLocationListener {
39 | private EditText etRadius;
40 | private TextView tvReult;
41 | private CheckBox cbAlertIn;
42 | private CheckBox cbAlertOut;
43 | private Button btFence;
44 |
45 | // 声明一个单次定位的客户端,获取当前位置的坐标,用于设置围栏的中心点坐标
46 | private AMapLocationClient onceClient = null;
47 | // 声明一个持续定位的客户端,用于添加地理围栏
48 | private AMapLocationClient locationClient = null;
49 | private AMapLocationClientOption locationOption = null;
50 |
51 | // 用于接收地理围栏提醒的pendingIntent
52 | private PendingIntent mPendingIntent = null;
53 | public static final String GEOFENCE_BROADCAST_ACTION = "com.location.apis.geofencedemo.broadcast";
54 |
55 | @Override
56 | protected void onCreate(Bundle savedInstanceState) {
57 | super.onCreate(savedInstanceState);
58 | setContentView(R.layout.activity_geofence_old);
59 | setTitle(R.string.oldGeoFence);
60 |
61 | etRadius = (EditText) findViewById(R.id.et_radius);
62 | cbAlertIn = (CheckBox) findViewById(R.id.cb_alertIn);
63 | cbAlertOut = (CheckBox) findViewById(R.id.cb_alertOut);
64 | tvReult = (TextView) findViewById(R.id.tv_result);
65 | btFence = (Button) findViewById(R.id.bt_fence);
66 |
67 | btFence.setOnClickListener(this);
68 |
69 | IntentFilter fliter = new IntentFilter(
70 | ConnectivityManager.CONNECTIVITY_ACTION);
71 | fliter.addAction(GEOFENCE_BROADCAST_ACTION);
72 | registerReceiver(mGeoFenceReceiver, fliter);
73 | Intent intent = new Intent(GEOFENCE_BROADCAST_ACTION);
74 | mPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
75 | intent, 0);
76 | onceClient = new AMapLocationClient(getApplicationContext());
77 | locationClient = new AMapLocationClient(this.getApplicationContext());
78 | locationOption = new AMapLocationClientOption();
79 |
80 | // 设置定位模式高精度,添加地理围栏最好设置成高精度模式
81 | locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
82 | // 设置定位监听
83 | locationClient.setLocationListener(this);
84 |
85 | AMapLocationClientOption onceOption = new AMapLocationClientOption();
86 | onceOption.setOnceLocation(true);
87 | onceClient.setLocationOption(onceOption);
88 | onceClient.setLocationListener(new AMapLocationListener() {
89 | @Override
90 | public void onLocationChanged(AMapLocation loc) {
91 | if (loc != null) {
92 | if (loc.getErrorCode() == 0) {
93 | if (null != locationClient) {
94 | float radius = 1000;
95 | String strRadius = etRadius.getText().toString();
96 | if (!TextUtils.isEmpty(strRadius)) {
97 | radius = Float.valueOf(strRadius);
98 | }
99 |
100 | // 添加地理围栏,
101 | // 第一个参数:围栏ID,可以自定义ID,示例中为了方便只使用一个ID;第二个:纬度;第三个:精度;
102 | // 第四个:半径;第五个:过期时间,单位毫秒,-1代表不过期;第六个:接收触发消息的PendingIntent
103 | locationClient.addGeoFenceAlert("fenceId",
104 | loc.getLatitude(), loc.getLongitude(),
105 | radius, -1, mPendingIntent);
106 | }
107 | } else {
108 | Toast.makeText(getApplicationContext(), "获取当前位置失败!",
109 | Toast.LENGTH_SHORT).show();
110 |
111 | Message msg = mHandler.obtainMessage();
112 | msg.obj = loc;
113 | msg.what = -1;
114 | mHandler.sendMessage(msg);
115 | }
116 | }
117 | }
118 | });
119 | }
120 |
121 | Handler mHandler = new Handler() {
122 | public void dispatchMessage(android.os.Message msg) {
123 | switch (msg.what) {
124 | case 1:
125 | tvReult.setText("进入围栏区域");
126 | break;
127 | case 2:
128 | tvReult.setText("离开围栏区域");
129 | break;
130 | case -1:
131 | // 获取当前位置失败
132 | AMapLocation loc = (AMapLocation) msg.obj;
133 | tvReult.setText(Utils.getLocationStr(loc));
134 | btFence.setText(getResources().getString(R.string.addFence));
135 | break;
136 | default:
137 | break;
138 | }
139 | };
140 | };
141 |
142 | private BroadcastReceiver mGeoFenceReceiver = new BroadcastReceiver() {
143 | @Override
144 | public void onReceive(Context context, Intent intent) {
145 | // 接收广播
146 | if (intent.getAction().equals(GEOFENCE_BROADCAST_ACTION)) {
147 | Bundle bundle = intent.getExtras();
148 | // 根据广播的event来确定是在区域内还是在区域外
149 | int status = bundle.getInt(GeoFence.BUNDLE_KEY_FENCESTATUS);
150 | String geoFenceId = bundle.getString(GeoFence.BUNDLE_KEY_FENCEID);
151 | if (status == 1) {
152 | // 进入围栏区域
153 | // 可以自定义提醒方式,示例中使用的是文字方式
154 | if (cbAlertIn.isChecked()) {
155 | mHandler.sendEmptyMessage(1);
156 | }
157 | } else if (status == 2) {
158 | // 离开围栏区域
159 | // 可以自定义提醒方式,示例中使用的是文字方式
160 | if (cbAlertOut.isChecked()) {
161 | mHandler.sendEmptyMessage(2);
162 | }
163 | }
164 | }
165 | }
166 | };
167 |
168 | @Override
169 | protected void onDestroy() {
170 | super.onDestroy();
171 | if (null != locationClient) {
172 | /**
173 | * 如果AMapLocationClient是在当前Activity实例化的,
174 | * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
175 | */
176 | locationClient.onDestroy();
177 | locationClient = null;
178 | locationOption = null;
179 | }
180 |
181 | if (null != onceClient) {
182 | onceClient.onDestroy();
183 | }
184 | }
185 |
186 | @Override
187 | public void onClick(View v) {
188 | if (v.getId() == R.id.bt_fence) {
189 | if (btFence.getText().equals(
190 | getResources().getString(R.string.addFence))) {
191 | btFence.setText(getResources().getString(R.string.removeFence));
192 | // 启动单次定位,获取当前位置
193 | onceClient.startLocation();
194 |
195 | // 设置定位参数
196 | locationClient.setLocationOption(locationOption);
197 | // 启动定位,地理围栏依赖于持续定位
198 | locationClient.startLocation();
199 |
200 | } else {
201 | tvReult.setText("");
202 | btFence.setText(getResources().getString(R.string.addFence));
203 | // 移除围栏
204 | locationClient.removeGeoFenceAlert(mPendingIntent);
205 | }
206 | }
207 | }
208 |
209 | // 定位监听
210 | @Override
211 | public void onLocationChanged(AMapLocation loc) {
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/LastLocation_Activity.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 | import com.amap.api.location.AMapLocation;
7 | import com.amap.api.location.AMapLocationClient;
8 |
9 | import android.app.Activity;
10 | import android.os.Bundle;
11 | import android.view.View;
12 | import android.view.View.OnClickListener;
13 | import android.widget.Button;
14 | import android.widget.TextView;
15 |
16 | /**
17 | * 最后位置功能演示
18 | * @创建时间:2016年1月7日 下午4:36:22
19 | * @项目名称: AMapLocationDemo2.x
20 | * @author hongming.wang
21 | * @文件名称:LastLocation_Activity.java
22 | * @类型名称:LastLocation_Activity
23 | * @since 2.3.0
24 | */
25 | public class LastLocation_Activity extends CheckPermissionsActivity implements OnClickListener{
26 | private Button btnLastLoc;
27 | private TextView tvReult;
28 | private AMapLocationClient locationClient = null;
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_lastlocation);
33 | setTitle(R.string.title_lastLocation);
34 | tvReult = (TextView) findViewById(R.id.tv_result);
35 | btnLastLoc = (Button) findViewById(R.id.bt_lastLoc);
36 | btnLastLoc.setOnClickListener(this);
37 | locationClient = new AMapLocationClient(this.getApplicationContext());
38 | }
39 |
40 | @Override
41 | protected void onDestroy() {
42 | super.onDestroy();
43 | if (null != locationClient) {
44 | locationClient.onDestroy();
45 | locationClient = null;
46 | }
47 | }
48 |
49 | @Override
50 | public void onClick(View v) {
51 | if(v.getId() == R.id.bt_lastLoc){
52 | AMapLocation location = locationClient.getLastKnownLocation();
53 | String result = Utils.getLocationStr(location);
54 | tvReult.setText(result);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/StartActivity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.location.demo.view.FeatureView;
4 |
5 | import android.app.ListActivity;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ArrayAdapter;
12 | import android.widget.ListAdapter;
13 | import android.widget.ListView;
14 |
15 | /**
16 | * 高德定位SDK功能接口实例 更多SDK请进入官网“http://lbs.amap.com/api/”查看
17 | * 官方论坛:http://lbsbbs.amap.com/portal.php
18 | *
19 | * @项目名称: AMapLocationDemo2.x
20 | *
21 | * @author hongming.wang
22 | * @文件名称: StartActivity.java
23 | * @类型名称: StartActivity
24 | */
25 | public class StartActivity extends ListActivity {
26 | private static class DemoDetails {
27 | private final int titleId;
28 | private final int descriptionId;
29 | private final Class extends android.app.Activity> activityClass;
30 | public DemoDetails(int titleId, int descriptionId,
31 | Class extends android.app.Activity> activityClass) {
32 | super();
33 | this.titleId = titleId;
34 | this.descriptionId = descriptionId;
35 | this.activityClass = activityClass;
36 | }
37 | }
38 |
39 | private static class CustomArrayAdapter extends ArrayAdapter {
40 | public CustomArrayAdapter(Context context, DemoDetails[] demos) {
41 | super(context, R.layout.feature, R.id.title, demos);
42 | }
43 |
44 | @Override
45 | public View getView(int position, View convertView, ViewGroup parent) {
46 | FeatureView featureView;
47 | if (convertView instanceof FeatureView) {
48 | featureView = (FeatureView) convertView;
49 | } else {
50 | featureView = new FeatureView(getContext());
51 | }
52 | DemoDetails demo = getItem(position);
53 | featureView.setTitleId(demo.titleId);
54 | featureView.setDescriptionId(demo.descriptionId);
55 | return featureView;
56 | }
57 | }
58 |
59 | private static final DemoDetails[] demos = {
60 | new DemoDetails(R.string.location,
61 | R.string.location_dec, Location_Activity.class),
62 | new DemoDetails(R.string.geoFence, R.string.geoFence_dec,
63 | GeoFence_Activity.class),
64 | new DemoDetails(R.string.assistantLocation,
65 | R.string.assistantLocation_dec,
66 | Assistant_Location_Activity.class),
67 | new DemoDetails(R.string.tools, R.string.tools_dec,
68 | Tools_Activity.class),
69 | new DemoDetails(R.string.lastLocation, R.string.lastLocation_dec,
70 | LastLocation_Activity.class),
71 | new DemoDetails(R.string.alarmCPU, R.string.alarmCPU_dec,
72 | Alarm_Location_Activity.class),
73 | new DemoDetails(R.string.errorCode, R.string.errorCode_dec,
74 | ErrorCode_Activity.class),
75 | };
76 |
77 | @Override
78 | protected void onCreate(Bundle savedInstanceState) {
79 | super.onCreate(savedInstanceState);
80 | setContentView(R.layout.activity_start);
81 | /**
82 | * setApiKey必须在启动Activity或者Application的onCreate里进行, 在其他地方使用有可能无效,
83 | * 如果使用setApiKey设置key,则AndroidManifest.xml里的key会失效
84 | */
85 | // AMapLocationClient.setApiKey("需要更换的key");
86 |
87 | setTitle(R.string.title_main);
88 | ListAdapter adapter = new CustomArrayAdapter(
89 | this.getApplicationContext(), demos);
90 | setListAdapter(adapter);
91 | // permChecker = new PermissionsChecker(this);
92 | }
93 |
94 | @Override
95 | public void onBackPressed() {
96 | super.onBackPressed();
97 | System.exit(0);
98 | }
99 |
100 | @Override
101 | protected void onListItemClick(ListView l, View v, int position, long id) {
102 | DemoDetails demo = (DemoDetails) getListAdapter().getItem(position);
103 | startActivity(
104 | new Intent(this.getApplicationContext(), demo.activityClass));
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/Tools_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.location.CoordinateConverter;
4 | import com.amap.api.location.CoordinateConverter.CoordType;
5 | import com.amap.api.location.DPoint;
6 |
7 | import android.app.Activity;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.view.View.OnClickListener;
11 | import android.widget.Button;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | /**
16 | * 高精度定位模式功能演示
17 | *
18 | * @创建时间: 2015年11月24日 下午5:22:42
19 | * @项目名称: AMapLocationDemo2.x
20 | * @author hongming.wang
21 | * @文件名称: Hight_Accuracy_Activity.java
22 | * @类型名称: Hight_Accuracy_Activity
23 | */
24 | public class Tools_Activity extends Activity
25 | implements OnClickListener {
26 | private TextView tvConvertReult;
27 | private TextView tvCheckReult;
28 |
29 | private Button btConvert;
30 | private Button btCheck;
31 | //构造一个示例坐标,第一个参数是纬度,第二个参数是经度
32 | DPoint examplePoint = new DPoint(39.911127, 116.433608);
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_tools);
38 | setTitle(R.string.title_tools);
39 |
40 | initView();
41 | }
42 |
43 | // 初始化控件
44 | private void initView() {
45 |
46 | tvConvertReult = (TextView) findViewById(R.id.tv_convertResult);
47 | tvCheckReult = (TextView) findViewById(R.id.tv_checkResult);
48 |
49 | btConvert = (Button) findViewById(R.id.bt_covert);
50 | btCheck = (Button) findViewById(R.id.bt_check);
51 |
52 | btConvert.setOnClickListener(this);
53 | btCheck.setOnClickListener(this);
54 | }
55 |
56 | @Override
57 | protected void onDestroy() {
58 | super.onDestroy();
59 | }
60 |
61 | @Override
62 | public void onClick(View v) {
63 | switch (v.getId()) {
64 | case R.id.bt_covert :
65 | convert();
66 | break;
67 | case R.id.bt_check :
68 | checkIsAvaliable();
69 | break;
70 | }
71 | }
72 |
73 | //坐标转换
74 | private void convert() {
75 | try{
76 | //初始化坐标转换类
77 | CoordinateConverter converter = new CoordinateConverter(
78 | getApplicationContext());
79 | /**
80 | * 设置坐标来源,这里使用百度坐标作为示例
81 | * 可选的来源包括:
82 | * CoordType.BAIDU : 百度坐标
83 | * CoordType.MAPBAR : 图吧坐标
84 | * CoordType.MAPABC : 图盟坐标
85 | * CoordType.SOSOMAP : 搜搜坐标
86 | * CoordType.ALIYUN : 阿里云坐标
87 | * CoordType.GOOGLE : 谷歌坐标
88 | * CoordType.GPS : GPS坐标
89 | */
90 | converter.from(CoordType.BAIDU);
91 | //设置需要转换的坐标
92 | converter.coord(examplePoint);
93 | //转换成高德坐标
94 | DPoint destPoint = converter.convert();
95 | if(null != destPoint){
96 | tvConvertReult.setText("转换后坐标(经度、纬度):" + destPoint.getLongitude() + "," + destPoint.getLatitude());
97 | } else {
98 | Toast.makeText(getApplicationContext(), "坐标转换失败", Toast.LENGTH_SHORT).show();
99 | }
100 | }catch(Exception e){
101 | Toast.makeText(getApplicationContext(), "坐标转换失败", Toast.LENGTH_SHORT).show();
102 | e.printStackTrace();
103 | }
104 | }
105 |
106 | //判断坐标是否高德地图可用
107 | private void checkIsAvaliable(){
108 | //初始化坐标工具类
109 | CoordinateConverter converter = new CoordinateConverter(
110 | getApplicationContext());
111 | //判断是否高德地图可用的坐标
112 | boolean result = converter.isAMapDataAvailable(examplePoint.getLatitude(), examplePoint.getLongitude());
113 | if(result){
114 | tvCheckReult.setText("该坐标是高德地图可用坐标");
115 | } else {
116 | tvCheckReult.setText("该坐标不能用于高德地图");
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/Utils.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 | import java.text.SimpleDateFormat;
7 | import java.util.Locale;
8 |
9 | import com.amap.api.location.AMapLocation;
10 |
11 | import android.text.TextUtils;
12 |
13 | /**
14 | * 辅助工具类
15 | * @创建时间: 2015年11月24日 上午11:46:50
16 | * @项目名称: AMapLocationDemo2.x
17 | * @author hongming.wang
18 | * @文件名称: Utils.java
19 | * @类型名称: Utils
20 | */
21 | public class Utils {
22 | /**
23 | * 开始定位
24 | */
25 | public final static int MSG_LOCATION_START = 0;
26 | /**
27 | * 定位完成
28 | */
29 | public final static int MSG_LOCATION_FINISH = 1;
30 | /**
31 | * 停止定位
32 | */
33 | public final static int MSG_LOCATION_STOP= 2;
34 |
35 | public final static String KEY_URL = "URL";
36 | public final static String URL_H5LOCATION = "file:///android_asset/location.html";
37 | /**
38 | * 根据定位结果返回定位信息的字符串
39 | * @param loc
40 | * @return
41 | */
42 | public synchronized static String getLocationStr(AMapLocation location){
43 | if(null == location){
44 | return null;
45 | }
46 | StringBuffer sb = new StringBuffer();
47 | //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
48 | if(location.getErrorCode() == 0){
49 | sb.append("定位成功" + "\n");
50 | sb.append("定位类型: " + location.getLocationType() + "\n");
51 | sb.append("经 度 : " + location.getLongitude() + "\n");
52 | sb.append("纬 度 : " + location.getLatitude() + "\n");
53 | sb.append("精 度 : " + location.getAccuracy() + "米" + "\n");
54 | sb.append("提供者 : " + location.getProvider() + "\n");
55 |
56 | sb.append("速 度 : " + location.getSpeed() + "米/秒" + "\n");
57 | sb.append("角 度 : " + location.getBearing() + "\n");
58 | // 获取当前提供定位服务的卫星个数
59 | sb.append("星 数 : " + location.getSatellites() + "\n");
60 | sb.append("国 家 : " + location.getCountry() + "\n");
61 | sb.append("省 : " + location.getProvince() + "\n");
62 | sb.append("市 : " + location.getCity() + "\n");
63 | sb.append("城市编码 : " + location.getCityCode() + "\n");
64 | sb.append("区 : " + location.getDistrict() + "\n");
65 | sb.append("区域 码 : " + location.getAdCode() + "\n");
66 | sb.append("地 址 : " + location.getAddress() + "\n");
67 | sb.append("兴趣点 : " + location.getPoiName() + "\n");
68 | //定位完成的时间
69 | sb.append("定位时间: " + formatUTC(location.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n");
70 | } else {
71 | //定位失败
72 | sb.append("定位失败" + "\n");
73 | sb.append("错误码:" + location.getErrorCode() + "\n");
74 | sb.append("错误信息:" + location.getErrorInfo() + "\n");
75 | sb.append("错误描述:" + location.getLocationDetail() + "\n");
76 | }
77 | //定位之后的回调时间
78 | sb.append("回调时间: " + formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n");
79 | return sb.toString();
80 | }
81 |
82 | private static SimpleDateFormat sdf = null;
83 | public synchronized static String formatUTC(long l, String strPattern) {
84 | if (TextUtils.isEmpty(strPattern)) {
85 | strPattern = "yyyy-MM-dd HH:mm:ss";
86 | }
87 | if (sdf == null) {
88 | try {
89 | sdf = new SimpleDateFormat(strPattern, Locale.CHINA);
90 | } catch (Throwable e) {
91 | }
92 | } else {
93 | sdf.applyPattern(strPattern);
94 | }
95 | return sdf == null ? "NULL" : sdf.format(l);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/java/com/amap/location/demo/view/FeatureView.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo.view;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.widget.FrameLayout;
6 | import android.widget.TextView;
7 |
8 | import com.amap.location.demo.R;
9 |
10 | public final class FeatureView extends FrameLayout {
11 |
12 | public FeatureView(Context context) {
13 | super(context);
14 |
15 | LayoutInflater layoutInflater = (LayoutInflater) context
16 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
17 | layoutInflater.inflate(R.layout.feature, this);
18 | }
19 |
20 | public synchronized void setTitleId(int titleId) {
21 | ((TextView) (findViewById(R.id.title))).setText(titleId);
22 | }
23 |
24 | public synchronized void setDescriptionId(int descriptionId) {
25 | ((TextView) (findViewById(R.id.description))).setText(descriptionId);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/drawable-hdpi/gps_point.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/src/main/res/drawable-hdpi/gps_point.png
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/src/main/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_alarm_location.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
18 |
19 |
27 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
41 |
42 |
50 |
51 |
52 |
53 |
54 |
58 |
59 |
65 |
66 |
72 |
73 |
74 |
78 |
79 |
84 |
85 |
86 |
89 |
90 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_assistant_location.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
20 |
21 |
22 |
23 |
28 |
29 |
35 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_errcode.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
11 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_geofence.xml:
--------------------------------------------------------------------------------
1 |
8 |
13 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_geofence_new.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_geofence_old.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
17 |
18 |
23 |
24 |
32 |
33 |
34 |
35 |
36 |
42 |
43 |
44 |
47 |
48 |
54 |
55 |
62 |
63 |
64 |
68 |
69 |
74 |
75 |
76 |
81 |
82 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_lastlocation.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
11 |
16 |
17 |
18 |
22 |
23 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_location.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
13 |
14 |
19 |
20 |
21 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_start.xml:
--------------------------------------------------------------------------------
1 |
8 |
13 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/activity_tools.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
17 |
23 |
24 |
31 |
32 |
33 |
34 |
38 |
39 |
45 |
46 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/feature.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/plugin_geofence_map.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
15 |
16 |
17 |
22 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/plugin_geofence_option.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
34 |
39 |
40 |
45 |
46 |
51 |
52 |
53 |
57 |
58 |
62 |
63 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
83 |
84 |
90 |
91 |
98 |
99 |
100 |
104 |
105 |
112 |
113 |
120 |
121 |
122 |
123 |
124 |
129 |
130 |
135 |
136 |
143 |
144 |
150 |
151 |
157 |
158 |
159 |
165 |
166 |
171 |
172 |
179 |
180 |
187 |
188 |
189 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/layout/plugin_location_option.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
26 |
27 |
34 |
35 |
36 |
41 |
42 |
47 |
48 |
56 |
57 |
58 |
59 |
60 |
61 |
64 |
65 |
69 |
70 |
78 |
79 |
80 |
81 |
82 |
83 |
88 |
89 |
94 |
95 |
100 |
101 |
102 |
107 |
108 |
114 |
115 |
121 |
122 |
123 |
128 |
129 |
134 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #ebebeb
5 | #000000
6 | #C0C0C0
7 | #FFFFFF
8 | #FF0000
9 | #0079ff
10 |
11 | #00000000
12 |
13 | #ccebfc
14 | #024ca1
15 | #abdaf4
16 | #909090
17 | #FFFFFF
18 | #898989
19 | #333333
20 | #777777
21 | #c5c5c5
22 | #ededed
23 | #4c90f9
24 |
25 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 15sp
4 | 20sp
5 | 12sp
6 | 11sp
7 | 10dp
8 | 29dp
9 | 85dp
10 |
11 | 25dp
12 | 11sp
13 | 12sp
14 | 13sp
15 | 14sp
16 | 15sp
17 | 16sp
18 | 17sp
19 | 18sp
20 |
21 | 20sp
22 | 16sp
23 | 15dp
24 | 15dp
25 | 2dp
26 |
27 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 高德定位SDK示例
5 | 高德定位SDK功能展示
6 |
7 | 获取定位数据
8 | 获取定位数据
9 | 调用定位接口获取定位数据
10 |
11 | 地理围栏
12 | 地理围栏
13 | 展示地理围栏功能
14 |
15 | 圆形地理围栏
16 | 展示圆形地理围栏
17 |
18 | 多边形地理围栏
19 | 展示多边形地理围栏
20 |
21 | 关键字地理围栏
22 | 展示关键字地理围栏
23 |
24 | 周边地理围栏
25 | 展示周边地理围栏
26 |
27 | 行政区划地理围栏
28 | 展示行政区划地理围栏
29 |
30 | 综合展示
31 | 综合展示地理围栏的功能
32 |
33 |
34 | 旧版地理围栏
35 | 旧版地理围栏,不建议使用
36 |
37 |
38 |
39 | H5辅助定位
40 | H5辅助定位
41 | 展示H5辅助定位功能
42 |
43 | 地图计算工具
44 | 地图计算工具
45 | 坐标转换等功能演示
46 |
47 | 获取最后一次位置
48 | 获取最后一次位置
49 | 获取最后一次定位的位置,此位置是一个历史位置
50 |
51 |
52 | 定时唤起CPU
53 | 定时唤起cpu
54 | 通过一个闹钟程序后台定时唤起cpu
55 |
56 | 错误码说明
57 | 错误码说明
58 | 错误码说明以及对应的解决方法
59 |
60 | 2000
61 | 30000
62 |
63 | 低功耗模式
64 | 仅设备模式
65 | 高精度模式
66 | 定位周期(ms)
67 | 网络超时(ms)
68 | 单次定位
69 | 逆地理编码
70 | 开启缓存
71 | 提高首次定位精度
72 | GPS优先
73 | 使用传感器
74 | 开启wifi扫描
75 |
76 | 唤醒周期(s)
77 |
78 | 开始定位
79 | 停止定位
80 |
81 | 围栏半径
82 | 米
83 | 触发条件
84 | 进入
85 | 离开
86 | 停留
87 | 添加围栏
88 | 移除围栏
89 |
90 | 隐藏设置
91 | 显示设置
92 |
93 | 显示列表
94 | 隐藏列表
95 |
96 | 圆形围栏
97 | 多边形
98 | 关键字围栏
99 | 周边围栏
100 | 行政区划围栏
101 |
102 | 获取最后位置
103 |
104 | 启动H5辅助定位
105 | 停止H5辅助定位
106 | 浏览器定位
107 | 辅助定位已经启动,请点击模拟浏览器请求或者在浏览器中输入http://127.0.0.1:43689/进行测试
108 |
109 | 坐标转换
110 | 位置区域判断
111 |
112 | 提示
113 | 当前应用缺少必要权限。\n\n请点击\"设置\"-\"权限\"-打开所需权限。
114 | 设置
115 | 取消
116 |
117 |
118 |
119 |
120 |
121 |
122 | 0 定位成功。 可以在定位回调里判断定位返回成功后再进行业务逻辑运算\n
123 | 1 一些重要参数为空,如context; 请对定位传递的参数进行非空判断\n
124 | 2 定位失败,由于仅扫描到单个wifi,且没有基站信息。 请重新尝试\n
125 | 3 获取到的请求参数为空,可能获取过程中出现异常。 请对所连接网络进行全面检查,请求可能被篡改\n
126 | 4 请求服务器过程中的异常,多为网络情况差,链路不通导致 请检查设备网络是否通畅\n
127 | 5 返回的XML格式错误,解析失败。 请稍后再试\n
128 | 6 定位服务返回定位失败。 请将errorDetail(通过getLocationDetail()方法获取)信息通过工单系统反馈给我们\n
129 | 7 KEY鉴权失败。 请仔细检查key绑定的sha1值与apk签名sha1值是否对应,或通过高频问题查找相关解决办法\n
130 | 8 Android exception常规错误 请将errordetail(通过getLocationDetail()方法获取)信息通过工单系统反馈给我们\n
131 | 9 定位初始化时出现异常。 请重新启动定位\n
132 | 10 定位客户端启动失败。 请检查AndroidManifest.xml文件是否配置了APSService定位服务\n
133 | 11 定位时的基站信息错误。 请检查是否安装SIM卡,设备很有可能连入了伪基站网络\n
134 | 12 缺少定位权限。 请在设备的设置中开启app的定位权限\n
135 | 13 定位失败,由于设备未开启WIFI模块或未插入SIM卡,且GPS当前不可用。 建议开启设备的WIFI模块,并将设备中插入一张可以正常工作的SIM卡,或者检查GPS是否开启;如果以上都内容都确认无误,请您检查App是否被授予定位权限\n
136 | 14 GPS 定位失败,由于设备当前 GPS 状态差。 建议持设备到相对开阔的露天场所再次尝试\n
137 | 15 定位结果被模拟导致定位失败。 如果您希望位置被模拟,请通过setMockEnable(true);方法开启允许位置模拟\n
138 | 16 当前POI检索条件、行政区划检索条件下,无可用地理围栏。 建议调整检索条件后重新尝试,例如调整POI关键字,调整POI类型,调整周边搜区域,调整行政区关键字等\n
139 | 17 相同的地理围栏已经存在,无需重复添加\n
140 |
141 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/app/src/test/java/com/amap/location/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 |
4 |
5 | /**
6 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
7 | */
8 | public class ExampleUnitTest {
9 |
10 | }
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/android_studio/AMapLocationDemo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Oct 10 19:14:12 CST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/android_studio/AMapLocationDemo/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/android_studio/Readme.md:
--------------------------------------------------------------------------------
1 | #AndroidStudio工程
2 | 目录结构符合AndroidStudio工程结构,适合使用AndroidStudio编译、运行
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/.gitignore:
--------------------------------------------------------------------------------
1 | gen
2 | bin
3 | /local.properties
4 | .DS_Store
5 | /build
6 | /captures
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | AMapLocationDemo
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
55 |
56 |
59 |
60 |
61 |
62 |
63 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
79 |
80 |
85 |
86 |
91 |
92 |
97 |
98 |
103 |
104 |
109 |
110 |
115 |
116 |
121 |
122 |
127 |
128 |
133 |
134 |
139 |
140 |
145 |
146 |
151 |
152 |
157 |
158 |
159 |
160 |
161 |
162 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/assets/location.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | 浏览器定位
8 |
9 |
10 |
11 |
12 |
13 |
14 |
48 |
49 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/ic_launcher-web.png
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/libs/AMap_Location_V3.3.0_20170118.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/libs/AMap_Location_V3.3.0_20170118.jar
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/libs/Android_Map3D_SDK_V4.1.2_20161104.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/libs/Android_Map3D_SDK_V4.1.2_20161104.jar
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/libs/armeabi/libgdinamapv4sdk752.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/libs/armeabi/libgdinamapv4sdk752.so
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/libs/armeabi/libgdinamapv4sdk752ex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/libs/armeabi/libgdinamapv4sdk752ex.so
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/proguard-project.txt:
--------------------------------------------------------------------------------
1 | #
2 | # Proguard config for the demo project.
3 | #
4 |
5 | # Standard config from ADT
6 |
7 | -optimizationpasses 5
8 | -dontusemixedcaseclassnames
9 | -dontskipnonpubliclibraryclasses
10 | -dontpreverify
11 | -verbose
12 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
13 | -ignorewarnings
14 |
15 | -libraryjars libs/AMap_Location_v2.0.0_20151117.jar
16 |
17 |
18 | -keep public class * extends android.app.Activity
19 | -keep public class * extends android.app.Application
20 | -keep public class * extends android.app.Service
21 | -keep public class * extends android.content.BroadcastReceiver
22 | -keep public class * extends android.content.ContentProvider
23 | -keep public class * extends android.app.backup.BackupAgentHelper
24 | -keep public class * extends android.preference.Preference
25 | -keep public class com.android.vending.licensing.ILicensingService
26 |
27 | -keepclasseswithmembernames class * {
28 | native ;
29 | }
30 |
31 | -keepclasseswithmembers class * {
32 | public (android.content.Context, android.util.AttributeSet);
33 | }
34 |
35 | -keepclasseswithmembers class * {
36 | public (android.content.Context, android.util.AttributeSet, int);
37 | }
38 |
39 | -keepclassmembers class * extends android.app.Activity {
40 | public void *(android.view.View);
41 | }
42 |
43 | -keepclassmembers enum * {
44 | public static **[] values();
45 | public static ** valueOf(java.lang.String);
46 | }
47 |
48 | -keep class * implements android.os.Parcelable {
49 | public static final android.os.Parcelable$Creator *;
50 | }
51 |
52 | # As described in tools/proguard/examples/android.pro - ignore all warnings.
53 | -dontwarn android.support.v4.**
54 | #如果有其它包有warning,在报出warning的包加入下面类似的-dontwarn 报名
55 | -dontwarn com.amap.api.**
56 | -dontwarn com.autonavi.aps.**
57 | #高德相关混淆文件
58 | #Location
59 | -keep class com.amap.api.location.**{*;}
60 | -keep class com.amap.api.fence.**{*;}
61 | -keep class com.autonavi.aps.amapapi.model.**{*;}
62 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-23
15 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/drawable-hdpi/gps_point.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/res/drawable-hdpi/gps_point.png
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amapapi/Android_Location_Demo/a1f994a22f3400556142d6273aa48e2de87040aa/eclipse/AMapLocationDemo/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_alarm_location.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
18 |
19 |
27 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
41 |
42 |
50 |
51 |
52 |
53 |
54 |
58 |
59 |
65 |
66 |
72 |
73 |
74 |
78 |
79 |
84 |
85 |
86 |
89 |
90 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_assistant_location.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
20 |
21 |
22 |
23 |
28 |
29 |
35 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_errcode.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
11 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_geofence.xml:
--------------------------------------------------------------------------------
1 |
8 |
13 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_geofence_new.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_geofence_old.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
17 |
18 |
23 |
24 |
32 |
33 |
34 |
35 |
36 |
42 |
43 |
44 |
47 |
48 |
54 |
55 |
62 |
63 |
64 |
68 |
69 |
74 |
75 |
76 |
81 |
82 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_lastlocation.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
11 |
16 |
17 |
18 |
22 |
23 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_location.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
13 |
14 |
19 |
20 |
21 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_start.xml:
--------------------------------------------------------------------------------
1 |
8 |
13 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/activity_tools.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
17 |
23 |
24 |
31 |
32 |
33 |
34 |
38 |
39 |
45 |
46 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/feature.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/plugin_geofence_map.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
15 |
16 |
17 |
22 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/plugin_geofence_option.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
34 |
39 |
40 |
45 |
46 |
51 |
52 |
53 |
57 |
58 |
62 |
63 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
83 |
84 |
90 |
91 |
98 |
99 |
100 |
104 |
105 |
112 |
113 |
120 |
121 |
122 |
123 |
124 |
129 |
130 |
135 |
136 |
143 |
144 |
150 |
151 |
157 |
158 |
159 |
165 |
166 |
171 |
172 |
179 |
180 |
187 |
188 |
189 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/layout/plugin_location_option.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
26 |
27 |
34 |
35 |
36 |
41 |
42 |
47 |
48 |
56 |
57 |
58 |
59 |
60 |
61 |
64 |
65 |
69 |
70 |
78 |
79 |
80 |
81 |
82 |
83 |
88 |
89 |
94 |
95 |
100 |
101 |
102 |
107 |
108 |
114 |
115 |
121 |
122 |
123 |
128 |
129 |
134 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #ebebeb
5 | #000000
6 | #C0C0C0
7 | #FFFFFF
8 | #FF0000
9 | #0079ff
10 |
11 | #00000000
12 |
13 | #ccebfc
14 | #024ca1
15 | #abdaf4
16 | #909090
17 | #FFFFFF
18 | #898989
19 | #333333
20 | #777777
21 | #c5c5c5
22 | #ededed
23 | #4c90f9
24 |
25 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 15sp
4 | 20sp
5 | 12sp
6 | 11sp
7 | 10dp
8 | 29dp
9 | 85dp
10 |
11 | 25dp
12 | 11sp
13 | 12sp
14 | 13sp
15 | 14sp
16 | 15sp
17 | 16sp
18 | 17sp
19 | 18sp
20 |
21 | 20sp
22 | 16sp
23 | 15dp
24 | 15dp
25 | 2dp
26 |
27 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 高德定位SDK示例
5 | 高德定位SDK功能展示
6 |
7 | 获取定位数据
8 | 获取定位数据
9 | 调用定位接口获取定位数据
10 |
11 | 地理围栏
12 | 地理围栏
13 | 展示地理围栏功能
14 |
15 | 圆形地理围栏
16 | 展示圆形地理围栏
17 |
18 | 多边形地理围栏
19 | 展示多边形地理围栏
20 |
21 | 关键字地理围栏
22 | 展示关键字地理围栏
23 |
24 | 周边地理围栏
25 | 展示周边地理围栏
26 |
27 | 行政区划地理围栏
28 | 展示行政区划地理围栏
29 |
30 | 综合展示
31 | 综合展示地理围栏的功能
32 |
33 |
34 | 旧版地理围栏
35 | 旧版地理围栏,不建议使用
36 |
37 |
38 |
39 | H5辅助定位
40 | H5辅助定位
41 | 展示H5辅助定位功能
42 |
43 | 地图计算工具
44 | 地图计算工具
45 | 坐标转换等功能演示
46 |
47 | 获取最后一次位置
48 | 获取最后一次位置
49 | 获取最后一次定位的位置,此位置是一个历史位置
50 |
51 |
52 | 定时唤起CPU
53 | 定时唤起cpu
54 | 通过一个闹钟程序后台定时唤起cpu
55 |
56 | 错误码说明
57 | 错误码说明
58 | 错误码说明以及对应的解决方法
59 |
60 | 2000
61 | 30000
62 |
63 | 低功耗模式
64 | 仅设备模式
65 | 高精度模式
66 | 定位周期(ms)
67 | 网络超时(ms)
68 | 单次定位
69 | 逆地理编码
70 | 开启缓存
71 | 提高首次定位精度
72 | GPS优先
73 | 使用传感器
74 | 开启wifi扫描
75 |
76 | 唤醒周期(s)
77 |
78 | 开始定位
79 | 停止定位
80 |
81 | 围栏半径
82 | 米
83 | 触发条件
84 | 进入
85 | 离开
86 | 停留
87 | 添加围栏
88 | 移除围栏
89 |
90 | 隐藏设置
91 | 显示设置
92 |
93 | 显示列表
94 | 隐藏列表
95 |
96 | 圆形围栏
97 | 多边形
98 | 关键字围栏
99 | 周边围栏
100 | 行政区划围栏
101 |
102 | 获取最后位置
103 |
104 | 启动H5辅助定位
105 | 停止H5辅助定位
106 | 浏览器定位
107 | 辅助定位已经启动,请点击模拟浏览器请求或者在浏览器中输入http://127.0.0.1:43689/进行测试
108 |
109 | 坐标转换
110 | 位置区域判断
111 |
112 | 提示
113 | 当前应用缺少必要权限。\n\n请点击\"设置\"-\"权限\"-打开所需权限。
114 | 设置
115 | 取消
116 |
117 |
118 |
119 |
120 |
121 |
122 | 0 定位成功。 可以在定位回调里判断定位返回成功后再进行业务逻辑运算\n
123 | 1 一些重要参数为空,如context; 请对定位传递的参数进行非空判断\n
124 | 2 定位失败,由于仅扫描到单个wifi,且没有基站信息。 请重新尝试\n
125 | 3 获取到的请求参数为空,可能获取过程中出现异常。 请对所连接网络进行全面检查,请求可能被篡改\n
126 | 4 请求服务器过程中的异常,多为网络情况差,链路不通导致 请检查设备网络是否通畅\n
127 | 5 返回的XML格式错误,解析失败。 请稍后再试\n
128 | 6 定位服务返回定位失败。 请将errorDetail(通过getLocationDetail()方法获取)信息通过工单系统反馈给我们\n
129 | 7 KEY鉴权失败。 请仔细检查key绑定的sha1值与apk签名sha1值是否对应,或通过高频问题查找相关解决办法\n
130 | 8 Android exception常规错误 请将errordetail(通过getLocationDetail()方法获取)信息通过工单系统反馈给我们\n
131 | 9 定位初始化时出现异常。 请重新启动定位\n
132 | 10 定位客户端启动失败。 请检查AndroidManifest.xml文件是否配置了APSService定位服务\n
133 | 11 定位时的基站信息错误。 请检查是否安装SIM卡,设备很有可能连入了伪基站网络\n
134 | 12 缺少定位权限。 请在设备的设置中开启app的定位权限\n
135 | 13 定位失败,由于设备未开启WIFI模块或未插入SIM卡,且GPS当前不可用。 建议开启设备的WIFI模块,并将设备中插入一张可以正常工作的SIM卡,或者检查GPS是否开启;如果以上都内容都确认无误,请您检查App是否被授予定位权限\n
136 | 14 GPS 定位失败,由于设备当前 GPS 状态差。 建议持设备到相对开阔的露天场所再次尝试\n
137 | 15 定位结果被模拟导致定位失败。 如果您希望位置被模拟,请通过setMockEnable(true);方法开启允许位置模拟\n
138 | 16 当前POI检索条件、行政区划检索条件下,无可用地理围栏。 建议调整检索条件后重新尝试,例如调整POI关键字,调整POI类型,调整周边搜区域,调整行政区关键字等\n
139 | 17 相同的地理围栏已经存在,无需重复添加\n
140 |
141 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/Alarm_Location_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.location.AMapLocation;
4 | import com.amap.api.location.AMapLocationClient;
5 | import com.amap.api.location.AMapLocationClientOption;
6 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode;
7 | import com.amap.api.location.AMapLocationListener;
8 |
9 | import android.app.Activity;
10 | import android.app.AlarmManager;
11 | import android.app.PendingIntent;
12 | import android.content.BroadcastReceiver;
13 | import android.content.Context;
14 | import android.content.Intent;
15 | import android.content.IntentFilter;
16 | import android.os.Bundle;
17 | import android.os.Handler;
18 | import android.os.Message;
19 | import android.os.SystemClock;
20 | import android.text.TextUtils;
21 | import android.view.View;
22 | import android.view.View.OnClickListener;
23 | import android.widget.Button;
24 | import android.widget.CheckBox;
25 | import android.widget.EditText;
26 | import android.widget.TextView;
27 | import android.widget.Toast;
28 |
29 | /**
30 | * 后台唤醒定位
31 | * @创建时间:2016年1月8日 上午11:25:01
32 | * @项目名称: AMapLocationDemo2.x
33 | * @author hongming.wang
34 | * @文件名称:Alarm_Location_Activity.java
35 | * @类型名称:Alarm_Location_Activity
36 | * @since 2.3.0
37 | */
38 | public class Alarm_Location_Activity extends CheckPermissionsActivity implements
39 | OnClickListener, AMapLocationListener {
40 | private EditText etInterval;
41 | private EditText etAlarm;
42 | private CheckBox cbAddress;
43 | private CheckBox cbGpsFirst;
44 | private TextView tvReult;
45 | private Button btLocation;
46 |
47 | private AMapLocationClient locationClient = null;
48 | private AMapLocationClientOption locationOption = null;
49 |
50 | private Intent alarmIntent = null;
51 | private PendingIntent alarmPi = null;
52 | private AlarmManager alarm = null;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.activity_alarm_location);
58 | setTitle(R.string.title_alarmCPU);
59 |
60 | etInterval = (EditText) findViewById(R.id.et_interval);
61 | etAlarm = (EditText) findViewById(R.id.et_alarm);
62 | cbAddress = (CheckBox) findViewById(R.id.cb_needAddress);
63 | cbGpsFirst = (CheckBox) findViewById(R.id.cb_gpsFirst);
64 | tvReult = (TextView) findViewById(R.id.tv_result);
65 | btLocation = (Button) findViewById(R.id.bt_location);
66 |
67 | btLocation.setOnClickListener(this);
68 |
69 | locationClient = new AMapLocationClient(this.getApplicationContext());
70 | locationOption = new AMapLocationClientOption();
71 | // 设置定位模式为高精度模式
72 | locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
73 | // 设置定位监听
74 | locationClient.setLocationListener(this);
75 |
76 | // 创建Intent对象,action为LOCATION
77 | alarmIntent = new Intent();
78 | alarmIntent.setAction("LOCATION");
79 | IntentFilter ift = new IntentFilter();
80 |
81 | // 定义一个PendingIntent对象,PendingIntent.getBroadcast包含了sendBroadcast的动作。
82 | // 也就是发送了action 为"LOCATION"的intent
83 | alarmPi = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
84 | // AlarmManager对象,注意这里并不是new一个对象,Alarmmanager为系统级服务
85 | alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
86 |
87 | //动态注册一个广播
88 | IntentFilter filter = new IntentFilter();
89 | filter.addAction("LOCATION");
90 | registerReceiver(alarmReceiver, filter);
91 | }
92 |
93 | @Override
94 | protected void onDestroy() {
95 | super.onDestroy();
96 | if (null != locationClient) {
97 | /**
98 | * 如果AMapLocationClient是在当前Activity实例化的,
99 | * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
100 | */
101 | locationClient.onDestroy();
102 | locationClient = null;
103 | locationOption = null;
104 | }
105 |
106 | if(null != alarmReceiver){
107 | unregisterReceiver(alarmReceiver);
108 | alarmReceiver = null;
109 | }
110 | }
111 |
112 | /**
113 | * 设置控件的可用状态
114 | */
115 | private void setViewEnable(boolean isEnable) {
116 | etInterval.setEnabled(isEnable);
117 | etAlarm.setEnabled(isEnable);
118 | cbAddress.setEnabled(isEnable);
119 | cbGpsFirst.setEnabled(isEnable);
120 | }
121 |
122 | @Override
123 | public void onClick(View v) {
124 | if (v.getId() == R.id.bt_location) {
125 | if (btLocation.getText().equals(
126 | getResources().getString(R.string.startLocation))) {
127 | setViewEnable(false);
128 | initOption();
129 | int alarmInterval = 5;
130 | String str = etAlarm.getText().toString();
131 | if(!TextUtils.isEmpty(str)){
132 | alarmInterval = Integer.parseInt(str);
133 | }
134 |
135 | btLocation.setText(getResources().getString(
136 | R.string.stopLocation));
137 | // 设置定位参数
138 | locationClient.setLocationOption(locationOption);
139 | // 启动定位
140 | locationClient.startLocation();
141 | mHandler.sendEmptyMessage(Utils.MSG_LOCATION_START);
142 |
143 | if(null != alarm){
144 | //设置一个闹钟,2秒之后每隔一段时间执行启动一次定位程序
145 | alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 2*1000,
146 | alarmInterval * 1000, alarmPi);
147 | }
148 | } else {
149 | setViewEnable(true);
150 | btLocation.setText(getResources().getString(
151 | R.string.startLocation));
152 | // 停止定位
153 | locationClient.stopLocation();
154 | mHandler.sendEmptyMessage(Utils.MSG_LOCATION_STOP);
155 |
156 | //停止定位的时候取消闹钟
157 | if(null != alarm){
158 | alarm.cancel(alarmPi);
159 | }
160 | }
161 | }
162 | }
163 |
164 | // 根据控件的选择,重新设置定位参数
165 | private void initOption() {
166 | // 设置是否需要显示地址信息
167 | locationOption.setNeedAddress(cbAddress.isChecked());
168 | /**
169 | * 设置是否优先返回GPS定位结果,如果30秒内GPS没有返回定位结果则进行网络定位
170 | * 注意:只有在高精度模式下的单次定位有效,其他方式无效
171 | */
172 | locationOption.setGpsFirst(cbGpsFirst.isChecked());
173 | String strInterval = etInterval.getText().toString();
174 | if (!TextUtils.isEmpty(strInterval)) {
175 | // 设置发送定位请求的时间间隔,最小值为1000,如果小于1000,按照1000算
176 | locationOption.setInterval(Long.valueOf(strInterval));
177 | }
178 |
179 | }
180 |
181 | Handler mHandler = new Handler() {
182 | public void dispatchMessage(android.os.Message msg) {
183 | switch (msg.what) {
184 | //开始定位
185 | case Utils.MSG_LOCATION_START:
186 | tvReult.setText("正在定位...");
187 | break;
188 | // 定位完成
189 | case Utils.MSG_LOCATION_FINISH:
190 | AMapLocation loc = (AMapLocation) msg.obj;
191 | String result = Utils.getLocationStr(loc);
192 | tvReult.setText(result);
193 | break;
194 | //停止定位
195 | case Utils.MSG_LOCATION_STOP:
196 | tvReult.setText("定位停止");
197 | break;
198 | default:
199 | break;
200 | }
201 | };
202 | };
203 |
204 | // 定位监听
205 | @Override
206 | public void onLocationChanged(AMapLocation loc) {
207 | if (null != loc) {
208 | Message msg = mHandler.obtainMessage();
209 | msg.obj = loc;
210 | msg.what = Utils.MSG_LOCATION_FINISH;
211 | mHandler.sendMessage(msg);
212 | }
213 | }
214 |
215 |
216 | private BroadcastReceiver alarmReceiver = new BroadcastReceiver(){
217 | @Override
218 | public void onReceive(Context context, Intent intent) {
219 | if(intent.getAction().equals("LOCATION")){
220 | if(null != locationClient){
221 | locationClient.startLocation();
222 | }
223 | }
224 | }
225 | };
226 |
227 | }
228 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/Assistant_Location_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.location.AMapLocationClient;
4 |
5 | import android.app.Activity;
6 | import android.graphics.Bitmap;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.view.View.OnClickListener;
10 | import android.view.Window;
11 | import android.webkit.GeolocationPermissions.Callback;
12 | import android.webkit.JsResult;
13 | import android.webkit.WebChromeClient;
14 | import android.webkit.WebSettings;
15 | import android.webkit.WebView;
16 | import android.webkit.WebViewClient;
17 | import android.widget.Button;
18 |
19 | /**
20 | * H5辅助定位模式功能演示
21 | *
22 | * @创建时间: 2015年11月24日 下午4:24:07
23 | * @项目名称: AMapLocationDemo2.x
24 | *
25 | * @author hongming.wang
26 | * @文件名称: Battery_Saving_Activity.java
27 | * @类型名称: Battery_Saving_Activity
28 | */
29 | public class Assistant_Location_Activity extends CheckPermissionsActivity implements OnClickListener {
30 | private Button btAssistant;
31 | private Button btLocation;
32 |
33 | private AMapLocationClient locationClient = null;
34 |
35 | private WebView webView;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_assistant_location);
41 | setTitle(R.string.title_assistantLocation);
42 |
43 | btAssistant = (Button) findViewById(R.id.bt_assistant);
44 | btLocation = (Button) findViewById(R.id.bt_location);
45 |
46 | locationClient = new AMapLocationClient(getApplicationContext());
47 | btAssistant.setOnClickListener(this);
48 | btLocation.setOnClickListener(this);
49 |
50 | initWebView();
51 | }
52 |
53 | private void initWebView(){
54 | webView = (WebView) findViewById(R.id.webView);
55 |
56 | WebSettings webSettings = webView.getSettings();
57 | // 允许webview执行javaScript脚本
58 | webSettings.setJavaScriptEnabled(true);
59 | // 设置是否允许定位,这里为了使用H5辅助定位,设置为false。
60 | //设置为true不一定会进行H5辅助定位,设置为true时只有H5定位失败后才会进行辅助定位
61 | webSettings.setGeolocationEnabled(false);
62 |
63 |
64 | webView.setWebViewClient(new WebViewClient() {
65 |
66 | public void onPageFinished(WebView view, String url) {
67 | super.onPageFinished(view, url);
68 | }
69 |
70 | public void onPageStarted(WebView view, String url, Bitmap favicon) {
71 | super.onPageStarted(view, url, favicon);
72 | }
73 | });
74 |
75 | webView.setWebChromeClient(new WebChromeClient() {
76 | // 处理javascript中的alert
77 | public boolean onJsAlert(WebView view, String url, String message,
78 | final JsResult result) {
79 | return true;
80 | };
81 |
82 | // 处理javascript中的confirm
83 | public boolean onJsConfirm(WebView view, String url,
84 | String message, final JsResult result) {
85 | return true;
86 | };
87 |
88 | // 处理定位权限请求
89 | @Override
90 | public void onGeolocationPermissionsShowPrompt(String origin,
91 | Callback callback) {
92 | callback.invoke(origin, true, false);
93 | super.onGeolocationPermissionsShowPrompt(origin, callback);
94 | }
95 | @Override
96 | // 设置网页加载的进度条
97 | public void onProgressChanged(WebView view, int newProgress) {
98 | Assistant_Location_Activity.this.getWindow().setFeatureInt(
99 | Window.FEATURE_PROGRESS, newProgress * 100);
100 | super.onProgressChanged(view, newProgress);
101 | }
102 |
103 | // 设置应用程序的标题title
104 | public void onReceivedTitle(WebView view, String title) {
105 | super.onReceivedTitle(view, title);
106 | }
107 | });
108 | }
109 |
110 | @Override
111 | protected void onDestroy() {
112 | super.onDestroy();
113 | if (null != locationClient) {
114 | locationClient.stopAssistantLocation();
115 | locationClient.onDestroy();
116 | }
117 | if(null != webView){
118 | webView.destroy();
119 | }
120 | }
121 |
122 | @Override
123 | public void onClick(View v) {
124 | if (v.getId() == R.id.bt_assistant) {
125 | if (btAssistant.getText().equals(getResources().getString(R.string.startAssistantLocation))) {
126 | btAssistant.setText(getResources().getString(R.string.stopAssistantLocation));
127 | locationClient.startAssistantLocation();
128 | btLocation.setEnabled(true);
129 | } else {
130 | btAssistant.setText(getResources().getString(R.string.startAssistantLocation));
131 | locationClient.stopAssistantLocation();
132 | btLocation.setEnabled(false);
133 | webView.setVisibility(View.GONE);
134 | }
135 | } else if (v.getId() == R.id.bt_location) {
136 | webView.setVisibility(View.VISIBLE);
137 | //浏览器定位,加载预置的H5定位页面
138 | webView.loadUrl(Utils.URL_H5LOCATION);
139 | }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/CheckPermissionsActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import android.Manifest;
10 | import android.app.Activity;
11 | import android.app.AlertDialog;
12 | import android.content.DialogInterface;
13 | import android.content.Intent;
14 | import android.content.pm.PackageManager;
15 | import android.net.Uri;
16 | import android.provider.Settings;
17 | import android.support.v4.app.ActivityCompat;
18 | import android.support.v4.content.ContextCompat;
19 | import android.view.KeyEvent;
20 |
21 | /**
22 | * 继承了Activity,实现Android6.0的运行时权限检测
23 | * 需要进行运行时权限检测的Activity可以继承这个类
24 | *
25 | * @创建时间:2016年5月27日 下午3:01:31
26 | * @项目名称: AMapLocationDemo
27 | * @author hongming.wang
28 | * @文件名称:PermissionsChecker.java
29 | * @类型名称:PermissionsChecker
30 | * @since 2.5.0
31 | */
32 | public class CheckPermissionsActivity extends Activity
33 | implements
34 | ActivityCompat.OnRequestPermissionsResultCallback {
35 | /**
36 | * 需要进行检测的权限数组
37 | */
38 | protected String[] needPermissions = {
39 | Manifest.permission.ACCESS_COARSE_LOCATION,
40 | Manifest.permission.ACCESS_FINE_LOCATION,
41 | Manifest.permission.WRITE_EXTERNAL_STORAGE,
42 | Manifest.permission.READ_EXTERNAL_STORAGE,
43 | Manifest.permission.READ_PHONE_STATE
44 | };
45 |
46 | private static final int PERMISSON_REQUESTCODE = 0;
47 |
48 | /**
49 | * 判断是否需要检测,防止不停的弹框
50 | */
51 | private boolean isNeedCheck = true;
52 |
53 | @Override
54 | protected void onResume() {
55 | super.onResume();
56 | if(isNeedCheck){
57 | checkPermissions(needPermissions);
58 | }
59 | }
60 |
61 | /**
62 | *
63 | * @param needRequestPermissonList
64 | * @since 2.5.0
65 | *
66 | */
67 | private void checkPermissions(String... permissions) {
68 | List needRequestPermissonList = findDeniedPermissions(permissions);
69 | if (null != needRequestPermissonList
70 | && needRequestPermissonList.size() > 0) {
71 | ActivityCompat.requestPermissions(this,
72 | needRequestPermissonList.toArray(
73 | new String[needRequestPermissonList.size()]),
74 | PERMISSON_REQUESTCODE);
75 | }
76 | }
77 |
78 | /**
79 | * 获取权限集中需要申请权限的列表
80 | *
81 | * @param permissions
82 | * @return
83 | * @since 2.5.0
84 | *
85 | */
86 | private List findDeniedPermissions(String[] permissions) {
87 | List needRequestPermissonList = new ArrayList();
88 | for (String perm : permissions) {
89 | if (ContextCompat.checkSelfPermission(this,
90 | perm) != PackageManager.PERMISSION_GRANTED
91 | || ActivityCompat.shouldShowRequestPermissionRationale(
92 | this, perm)) {
93 | needRequestPermissonList.add(perm);
94 | }
95 | }
96 | return needRequestPermissonList;
97 | }
98 |
99 | /**
100 | * 检测是否说有的权限都已经授权
101 | * @param grantResults
102 | * @return
103 | * @since 2.5.0
104 | *
105 | */
106 | private boolean verifyPermissions(int[] grantResults) {
107 | for (int result : grantResults) {
108 | if (result != PackageManager.PERMISSION_GRANTED) {
109 | return false;
110 | }
111 | }
112 | return true;
113 | }
114 |
115 | @Override
116 | public void onRequestPermissionsResult(int requestCode,
117 | String[] permissions, int[] paramArrayOfInt) {
118 | if (requestCode == PERMISSON_REQUESTCODE) {
119 | if (!verifyPermissions(paramArrayOfInt)) {
120 | showMissingPermissionDialog();
121 | isNeedCheck = false;
122 | }
123 | }
124 | }
125 |
126 | /**
127 | * 显示提示信息
128 | *
129 | * @since 2.5.0
130 | *
131 | */
132 | private void showMissingPermissionDialog() {
133 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
134 | builder.setTitle(R.string.notifyTitle);
135 | builder.setMessage(R.string.notifyMsg);
136 |
137 | // 拒绝, 退出应用
138 | builder.setNegativeButton(R.string.cancel,
139 | new DialogInterface.OnClickListener() {
140 | @Override
141 | public void onClick(DialogInterface dialog, int which) {
142 | finish();
143 | }
144 | });
145 |
146 | builder.setPositiveButton(R.string.setting,
147 | new DialogInterface.OnClickListener() {
148 | @Override
149 | public void onClick(DialogInterface dialog, int which) {
150 | startAppSettings();
151 | }
152 | });
153 |
154 | builder.setCancelable(false);
155 |
156 | builder.show();
157 | }
158 |
159 | /**
160 | * 启动应用的设置
161 | *
162 | * @since 2.5.0
163 | *
164 | */
165 | private void startAppSettings() {
166 | Intent intent = new Intent(
167 | Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
168 | intent.setData(Uri.parse("package:" + getPackageName()));
169 | startActivity(intent);
170 | }
171 |
172 | @Override
173 | public boolean onKeyDown(int keyCode, KeyEvent event) {
174 | if(keyCode == KeyEvent.KEYCODE_BACK){
175 | this.finish();
176 | return true;
177 | }
178 | return super.onKeyDown(keyCode, event);
179 | }
180 |
181 | }
182 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/Const.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import android.graphics.Color;
4 |
5 | /**
6 | * @since 3.3.0
7 | * Created by hongming.wang on 2016/12/19.
8 | */
9 |
10 | public class Const {
11 | /**
12 | * 地图中绘制多边形、圆形的边界颜色
13 | * @since 3.3.0
14 | */
15 | public static final int STROKE_COLOR = Color.argb(180, 63, 145, 252);
16 | /**
17 | * 地图中绘制多边形、圆形的填充颜色
18 | * @since 3.3.0
19 | */
20 | public static final int FILL_COLOR = Color.argb(163, 118, 212, 243);
21 |
22 | /**
23 | * 地图中绘制多边形、圆形的边框宽度
24 | * @since 3.3.0
25 | */
26 | public static final float STROKE_WIDTH = 5F;
27 | }
28 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/ErrorCode_Activity.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 |
7 | import android.app.Activity;
8 | import android.os.Bundle;
9 | import android.view.KeyEvent;
10 | import android.widget.TextView;
11 |
12 | /**
13 | * 错误码说明
14 | * @创建时间:2016年5月31日 上午11:22:06
15 | * @项目名称: AMapLocationDemo
16 | * @author hongming.wang
17 | * @文件名称:ErrorCodeInfo.java
18 | * @类型名称:ErrorCodeInfo
19 | * @since 2.5.0
20 | */
21 | public class ErrorCode_Activity extends Activity{
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_errcode);
27 | setTitle(R.string.title_errorCode);
28 | }
29 |
30 | @Override
31 | public boolean onKeyDown(int keyCode, KeyEvent event) {
32 | if(keyCode == KeyEvent.KEYCODE_BACK){
33 | this.finish();
34 | return true;
35 | }
36 | return super.onKeyDown(keyCode, event);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/GeoFence_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.location.demo.view.FeatureView;
4 |
5 | import android.app.ListActivity;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.view.KeyEvent;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.ListAdapter;
14 | import android.widget.ListView;
15 |
16 | /**
17 | * 地理围栏功能演示
18 | *
19 | * @创建时间: 2015年11月24日 下午5:49:52
20 | * @项目名称: AMapLocationDemo2.x
21 | * @author hongming.wang
22 | * @文件名称: GeoFence_Activity.java
23 | * @类型名称: GeoFence_Activity
24 | */
25 | public class GeoFence_Activity extends ListActivity {
26 | private static class DemoDetails {
27 | private final int titleId;
28 | private final int descriptionId;
29 | private final Class extends android.app.Activity> activityClass;
30 | public DemoDetails(int titleId, int descriptionId,
31 | Class extends android.app.Activity> activityClass) {
32 | super();
33 | this.titleId = titleId;
34 | this.descriptionId = descriptionId;
35 | this.activityClass = activityClass;
36 | }
37 | }
38 |
39 | private static class CustomArrayAdapter extends ArrayAdapter {
40 | public CustomArrayAdapter(Context context, DemoDetails[] demos) {
41 | super(context, R.layout.feature, R.id.title, demos);
42 | }
43 |
44 | @Override
45 | public View getView(int position, View convertView, ViewGroup parent) {
46 | FeatureView featureView;
47 | if (convertView instanceof FeatureView) {
48 | featureView = (FeatureView) convertView;
49 | } else {
50 | featureView = new FeatureView(getContext());
51 | }
52 | DemoDetails demo = getItem(position);
53 | featureView.setTitleId(demo.titleId);
54 | featureView.setDescriptionId(demo.descriptionId);
55 | return featureView;
56 | }
57 | }
58 |
59 | private static final DemoDetails[] demos = {
60 | new DemoDetails(R.string.roundGeoFence,
61 | R.string.roundGeoFence_dec, GeoFence_Round_Activity.class),
62 | new DemoDetails(R.string.polygonGeoFence,
63 | R.string.polygonGeoFence_dec, GeoFence_Polygon_Activity.class),
64 | new DemoDetails(R.string.keywordGeoFence,
65 | R.string.keywordGeoFence_dec, GeoFence_Keyword_Activity.class),
66 | new DemoDetails(R.string.nearbyGeoFence,
67 | R.string.nearbyGeoFence_dec, GeoFence_Nearby_Activity.class),
68 | new DemoDetails(R.string.districtGeoFence,
69 | R.string.districtGeoFence_dec, GeoFence_District_Activity.class),
70 | new DemoDetails(R.string.multipleGeoFence, R.string.multipleGeoFence_dec,
71 | GeoFence_Multiple_Activity.class),
72 | new DemoDetails(R.string.oldGeoFence, R.string.oldGeoFence_dec,
73 | GeoFence_Old_Activity.class),
74 | };
75 |
76 | @Override
77 | protected void onCreate(Bundle savedInstanceState) {
78 | super.onCreate(savedInstanceState);
79 | setContentView(R.layout.activity_geofence);
80 | setTitle(R.string.title_main);
81 | ListAdapter adapter = new CustomArrayAdapter(
82 | this.getApplicationContext(), demos);
83 | setListAdapter(adapter);
84 | // permChecker = new PermissionsChecker(this);
85 | }
86 |
87 | @Override
88 | public void onBackPressed() {
89 | super.onBackPressed();
90 | System.exit(0);
91 | }
92 |
93 | @Override
94 | protected void onListItemClick(ListView l, View v, int position, long id) {
95 | DemoDetails demo = (DemoDetails) getListAdapter().getItem(position);
96 | startActivity(
97 | new Intent(this.getApplicationContext(), demo.activityClass));
98 | }
99 | @Override
100 | public boolean onKeyDown(int keyCode, KeyEvent event) {
101 | if(keyCode == KeyEvent.KEYCODE_BACK){
102 | this.finish();
103 | return true;
104 | }
105 | return super.onKeyDown(keyCode, event);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/GeoFence_Old_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.fence.GeoFence;
4 | import com.amap.api.location.AMapLocation;
5 | import com.amap.api.location.AMapLocationClient;
6 | import com.amap.api.location.AMapLocationClientOption;
7 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode;
8 | import com.amap.api.location.AMapLocationListener;
9 |
10 | import android.app.PendingIntent;
11 | import android.content.BroadcastReceiver;
12 | import android.content.Context;
13 | import android.content.Intent;
14 | import android.content.IntentFilter;
15 | import android.net.ConnectivityManager;
16 | import android.os.Bundle;
17 | import android.os.Handler;
18 | import android.os.Message;
19 | import android.text.TextUtils;
20 | import android.view.View;
21 | import android.view.View.OnClickListener;
22 | import android.widget.Button;
23 | import android.widget.CheckBox;
24 | import android.widget.EditText;
25 | import android.widget.TextView;
26 | import android.widget.Toast;
27 |
28 | /**
29 | * 地理围栏功能演示
30 | *
31 | * @创建时间: 2015年11月24日 下午5:49:52
32 | * @项目名称: AMapLocationDemo2.x
33 | * @author hongming.wang
34 | * @文件名称: GeoFence_Activity.java
35 | * @类型名称: GeoFence_Activity
36 | */
37 | public class GeoFence_Old_Activity extends CheckPermissionsActivity implements OnClickListener,
38 | AMapLocationListener {
39 | private EditText etRadius;
40 | private TextView tvReult;
41 | private CheckBox cbAlertIn;
42 | private CheckBox cbAlertOut;
43 | private Button btFence;
44 |
45 | // 声明一个单次定位的客户端,获取当前位置的坐标,用于设置围栏的中心点坐标
46 | private AMapLocationClient onceClient = null;
47 | // 声明一个持续定位的客户端,用于添加地理围栏
48 | private AMapLocationClient locationClient = null;
49 | private AMapLocationClientOption locationOption = null;
50 |
51 | // 用于接收地理围栏提醒的pendingIntent
52 | private PendingIntent mPendingIntent = null;
53 | public static final String GEOFENCE_BROADCAST_ACTION = "com.location.apis.geofencedemo.broadcast";
54 |
55 | @Override
56 | protected void onCreate(Bundle savedInstanceState) {
57 | super.onCreate(savedInstanceState);
58 | setContentView(R.layout.activity_geofence_old);
59 | setTitle(R.string.oldGeoFence);
60 |
61 | etRadius = (EditText) findViewById(R.id.et_radius);
62 | cbAlertIn = (CheckBox) findViewById(R.id.cb_alertIn);
63 | cbAlertOut = (CheckBox) findViewById(R.id.cb_alertOut);
64 | tvReult = (TextView) findViewById(R.id.tv_result);
65 | btFence = (Button) findViewById(R.id.bt_fence);
66 |
67 | btFence.setOnClickListener(this);
68 |
69 | IntentFilter fliter = new IntentFilter(
70 | ConnectivityManager.CONNECTIVITY_ACTION);
71 | fliter.addAction(GEOFENCE_BROADCAST_ACTION);
72 | registerReceiver(mGeoFenceReceiver, fliter);
73 | Intent intent = new Intent(GEOFENCE_BROADCAST_ACTION);
74 | mPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
75 | intent, 0);
76 | onceClient = new AMapLocationClient(getApplicationContext());
77 | locationClient = new AMapLocationClient(this.getApplicationContext());
78 | locationOption = new AMapLocationClientOption();
79 |
80 | // 设置定位模式高精度,添加地理围栏最好设置成高精度模式
81 | locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
82 | // 设置定位监听
83 | locationClient.setLocationListener(this);
84 |
85 | AMapLocationClientOption onceOption = new AMapLocationClientOption();
86 | onceOption.setOnceLocation(true);
87 | onceClient.setLocationOption(onceOption);
88 | onceClient.setLocationListener(new AMapLocationListener() {
89 | @Override
90 | public void onLocationChanged(AMapLocation loc) {
91 | if (loc != null) {
92 | if (loc.getErrorCode() == 0) {
93 | if (null != locationClient) {
94 | float radius = 1000;
95 | String strRadius = etRadius.getText().toString();
96 | if (!TextUtils.isEmpty(strRadius)) {
97 | radius = Float.valueOf(strRadius);
98 | }
99 |
100 | // 添加地理围栏,
101 | // 第一个参数:围栏ID,可以自定义ID,示例中为了方便只使用一个ID;第二个:纬度;第三个:精度;
102 | // 第四个:半径;第五个:过期时间,单位毫秒,-1代表不过期;第六个:接收触发消息的PendingIntent
103 | locationClient.addGeoFenceAlert("fenceId",
104 | loc.getLatitude(), loc.getLongitude(),
105 | radius, -1, mPendingIntent);
106 | }
107 | } else {
108 | Toast.makeText(getApplicationContext(), "获取当前位置失败!",
109 | Toast.LENGTH_SHORT).show();
110 |
111 | Message msg = mHandler.obtainMessage();
112 | msg.obj = loc;
113 | msg.what = -1;
114 | mHandler.sendMessage(msg);
115 | }
116 | }
117 | }
118 | });
119 | }
120 |
121 | Handler mHandler = new Handler() {
122 | public void dispatchMessage(android.os.Message msg) {
123 | switch (msg.what) {
124 | case 1:
125 | tvReult.setText("进入围栏区域");
126 | break;
127 | case 2:
128 | tvReult.setText("离开围栏区域");
129 | break;
130 | case -1:
131 | // 获取当前位置失败
132 | AMapLocation loc = (AMapLocation) msg.obj;
133 | tvReult.setText(Utils.getLocationStr(loc));
134 | btFence.setText(getResources().getString(R.string.addFence));
135 | break;
136 | default:
137 | break;
138 | }
139 | };
140 | };
141 |
142 | private BroadcastReceiver mGeoFenceReceiver = new BroadcastReceiver() {
143 | @Override
144 | public void onReceive(Context context, Intent intent) {
145 | // 接收广播
146 | if (intent.getAction().equals(GEOFENCE_BROADCAST_ACTION)) {
147 | Bundle bundle = intent.getExtras();
148 | // 根据广播的event来确定是在区域内还是在区域外
149 | int status = bundle.getInt(GeoFence.BUNDLE_KEY_FENCESTATUS);
150 | String geoFenceId = bundle.getString(GeoFence.BUNDLE_KEY_FENCEID);
151 | if (status == 1) {
152 | // 进入围栏区域
153 | // 可以自定义提醒方式,示例中使用的是文字方式
154 | if (cbAlertIn.isChecked()) {
155 | mHandler.sendEmptyMessage(1);
156 | }
157 | } else if (status == 2) {
158 | // 离开围栏区域
159 | // 可以自定义提醒方式,示例中使用的是文字方式
160 | if (cbAlertOut.isChecked()) {
161 | mHandler.sendEmptyMessage(2);
162 | }
163 | }
164 | }
165 | }
166 | };
167 |
168 | @Override
169 | protected void onDestroy() {
170 | super.onDestroy();
171 | if (null != locationClient) {
172 | /**
173 | * 如果AMapLocationClient是在当前Activity实例化的,
174 | * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
175 | */
176 | locationClient.onDestroy();
177 | locationClient = null;
178 | locationOption = null;
179 | }
180 |
181 | if (null != onceClient) {
182 | onceClient.onDestroy();
183 | }
184 | }
185 |
186 | @Override
187 | public void onClick(View v) {
188 | if (v.getId() == R.id.bt_fence) {
189 | if (btFence.getText().equals(
190 | getResources().getString(R.string.addFence))) {
191 | btFence.setText(getResources().getString(R.string.removeFence));
192 | // 启动单次定位,获取当前位置
193 | onceClient.startLocation();
194 |
195 | // 设置定位参数
196 | locationClient.setLocationOption(locationOption);
197 | // 启动定位,地理围栏依赖于持续定位
198 | locationClient.startLocation();
199 |
200 | } else {
201 | tvReult.setText("");
202 | btFence.setText(getResources().getString(R.string.addFence));
203 | // 移除围栏
204 | locationClient.removeGeoFenceAlert(mPendingIntent);
205 | }
206 | }
207 | }
208 |
209 | // 定位监听
210 | @Override
211 | public void onLocationChanged(AMapLocation loc) {
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/LastLocation_Activity.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 | import com.amap.api.location.AMapLocation;
7 | import com.amap.api.location.AMapLocationClient;
8 |
9 | import android.app.Activity;
10 | import android.os.Bundle;
11 | import android.view.View;
12 | import android.view.View.OnClickListener;
13 | import android.widget.Button;
14 | import android.widget.TextView;
15 |
16 | /**
17 | * 最后位置功能演示
18 | * @创建时间:2016年1月7日 下午4:36:22
19 | * @项目名称: AMapLocationDemo2.x
20 | * @author hongming.wang
21 | * @文件名称:LastLocation_Activity.java
22 | * @类型名称:LastLocation_Activity
23 | * @since 2.3.0
24 | */
25 | public class LastLocation_Activity extends CheckPermissionsActivity implements OnClickListener{
26 | private Button btnLastLoc;
27 | private TextView tvReult;
28 | private AMapLocationClient locationClient = null;
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_lastlocation);
33 | setTitle(R.string.title_lastLocation);
34 | tvReult = (TextView) findViewById(R.id.tv_result);
35 | btnLastLoc = (Button) findViewById(R.id.bt_lastLoc);
36 | btnLastLoc.setOnClickListener(this);
37 | locationClient = new AMapLocationClient(this.getApplicationContext());
38 | }
39 |
40 | @Override
41 | protected void onDestroy() {
42 | super.onDestroy();
43 | if (null != locationClient) {
44 | locationClient.onDestroy();
45 | locationClient = null;
46 | }
47 | }
48 |
49 | @Override
50 | public void onClick(View v) {
51 | if(v.getId() == R.id.bt_lastLoc){
52 | AMapLocation location = locationClient.getLastKnownLocation();
53 | String result = Utils.getLocationStr(location);
54 | tvReult.setText(result);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/StartActivity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.location.demo.view.FeatureView;
4 |
5 | import android.app.ListActivity;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ArrayAdapter;
12 | import android.widget.ListAdapter;
13 | import android.widget.ListView;
14 |
15 | /**
16 | * 高德定位SDK功能接口实例 更多SDK请进入官网“http://lbs.amap.com/api/”查看
17 | * 官方论坛:http://lbsbbs.amap.com/portal.php
18 | *
19 | * @项目名称: AMapLocationDemo2.x
20 | *
21 | * @author hongming.wang
22 | * @文件名称: StartActivity.java
23 | * @类型名称: StartActivity
24 | */
25 | public class StartActivity extends ListActivity {
26 | private static class DemoDetails {
27 | private final int titleId;
28 | private final int descriptionId;
29 | private final Class extends android.app.Activity> activityClass;
30 | public DemoDetails(int titleId, int descriptionId,
31 | Class extends android.app.Activity> activityClass) {
32 | super();
33 | this.titleId = titleId;
34 | this.descriptionId = descriptionId;
35 | this.activityClass = activityClass;
36 | }
37 | }
38 |
39 | private static class CustomArrayAdapter extends ArrayAdapter {
40 | public CustomArrayAdapter(Context context, DemoDetails[] demos) {
41 | super(context, R.layout.feature, R.id.title, demos);
42 | }
43 |
44 | @Override
45 | public View getView(int position, View convertView, ViewGroup parent) {
46 | FeatureView featureView;
47 | if (convertView instanceof FeatureView) {
48 | featureView = (FeatureView) convertView;
49 | } else {
50 | featureView = new FeatureView(getContext());
51 | }
52 | DemoDetails demo = getItem(position);
53 | featureView.setTitleId(demo.titleId);
54 | featureView.setDescriptionId(demo.descriptionId);
55 | return featureView;
56 | }
57 | }
58 |
59 | private static final DemoDetails[] demos = {
60 | new DemoDetails(R.string.location,
61 | R.string.location_dec, Location_Activity.class),
62 | new DemoDetails(R.string.geoFence, R.string.geoFence_dec,
63 | GeoFence_Activity.class),
64 | new DemoDetails(R.string.assistantLocation,
65 | R.string.assistantLocation_dec,
66 | Assistant_Location_Activity.class),
67 | new DemoDetails(R.string.tools, R.string.tools_dec,
68 | Tools_Activity.class),
69 | new DemoDetails(R.string.lastLocation, R.string.lastLocation_dec,
70 | LastLocation_Activity.class),
71 | new DemoDetails(R.string.alarmCPU, R.string.alarmCPU_dec,
72 | Alarm_Location_Activity.class),
73 | new DemoDetails(R.string.errorCode, R.string.errorCode_dec,
74 | ErrorCode_Activity.class),
75 | };
76 |
77 | @Override
78 | protected void onCreate(Bundle savedInstanceState) {
79 | super.onCreate(savedInstanceState);
80 | setContentView(R.layout.activity_start);
81 | /**
82 | * setApiKey必须在启动Activity或者Application的onCreate里进行, 在其他地方使用有可能无效,
83 | * 如果使用setApiKey设置key,则AndroidManifest.xml里的key会失效
84 | */
85 | // AMapLocationClient.setApiKey("需要更换的key");
86 |
87 | setTitle(R.string.title_main);
88 | ListAdapter adapter = new CustomArrayAdapter(
89 | this.getApplicationContext(), demos);
90 | setListAdapter(adapter);
91 | // permChecker = new PermissionsChecker(this);
92 | }
93 |
94 | @Override
95 | public void onBackPressed() {
96 | super.onBackPressed();
97 | System.exit(0);
98 | }
99 |
100 | @Override
101 | protected void onListItemClick(ListView l, View v, int position, long id) {
102 | DemoDetails demo = (DemoDetails) getListAdapter().getItem(position);
103 | startActivity(
104 | new Intent(this.getApplicationContext(), demo.activityClass));
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/Tools_Activity.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo;
2 |
3 | import com.amap.api.location.CoordinateConverter;
4 | import com.amap.api.location.CoordinateConverter.CoordType;
5 | import com.amap.api.location.DPoint;
6 |
7 | import android.app.Activity;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.view.View.OnClickListener;
11 | import android.widget.Button;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | /**
16 | * 高精度定位模式功能演示
17 | *
18 | * @创建时间: 2015年11月24日 下午5:22:42
19 | * @项目名称: AMapLocationDemo2.x
20 | * @author hongming.wang
21 | * @文件名称: Hight_Accuracy_Activity.java
22 | * @类型名称: Hight_Accuracy_Activity
23 | */
24 | public class Tools_Activity extends Activity
25 | implements OnClickListener {
26 | private TextView tvConvertReult;
27 | private TextView tvCheckReult;
28 |
29 | private Button btConvert;
30 | private Button btCheck;
31 | //构造一个示例坐标,第一个参数是纬度,第二个参数是经度
32 | DPoint examplePoint = new DPoint(39.911127, 116.433608);
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_tools);
38 | setTitle(R.string.title_tools);
39 |
40 | initView();
41 | }
42 |
43 | // 初始化控件
44 | private void initView() {
45 |
46 | tvConvertReult = (TextView) findViewById(R.id.tv_convertResult);
47 | tvCheckReult = (TextView) findViewById(R.id.tv_checkResult);
48 |
49 | btConvert = (Button) findViewById(R.id.bt_covert);
50 | btCheck = (Button) findViewById(R.id.bt_check);
51 |
52 | btConvert.setOnClickListener(this);
53 | btCheck.setOnClickListener(this);
54 | }
55 |
56 | @Override
57 | protected void onDestroy() {
58 | super.onDestroy();
59 | }
60 |
61 | @Override
62 | public void onClick(View v) {
63 | switch (v.getId()) {
64 | case R.id.bt_covert :
65 | convert();
66 | break;
67 | case R.id.bt_check :
68 | checkIsAvaliable();
69 | break;
70 | }
71 | }
72 |
73 | //坐标转换
74 | private void convert() {
75 | try{
76 | //初始化坐标转换类
77 | CoordinateConverter converter = new CoordinateConverter(
78 | getApplicationContext());
79 | /**
80 | * 设置坐标来源,这里使用百度坐标作为示例
81 | * 可选的来源包括:
82 | * CoordType.BAIDU : 百度坐标
83 | * CoordType.MAPBAR : 图吧坐标
84 | * CoordType.MAPABC : 图盟坐标
85 | * CoordType.SOSOMAP : 搜搜坐标
86 | * CoordType.ALIYUN : 阿里云坐标
87 | * CoordType.GOOGLE : 谷歌坐标
88 | * CoordType.GPS : GPS坐标
89 | */
90 | converter.from(CoordType.BAIDU);
91 | //设置需要转换的坐标
92 | converter.coord(examplePoint);
93 | //转换成高德坐标
94 | DPoint destPoint = converter.convert();
95 | if(null != destPoint){
96 | tvConvertReult.setText("转换后坐标(经度、纬度):" + destPoint.getLongitude() + "," + destPoint.getLatitude());
97 | } else {
98 | Toast.makeText(getApplicationContext(), "坐标转换失败", Toast.LENGTH_SHORT).show();
99 | }
100 | }catch(Exception e){
101 | Toast.makeText(getApplicationContext(), "坐标转换失败", Toast.LENGTH_SHORT).show();
102 | e.printStackTrace();
103 | }
104 | }
105 |
106 | //判断坐标是否高德地图可用
107 | private void checkIsAvaliable(){
108 | //初始化坐标工具类
109 | CoordinateConverter converter = new CoordinateConverter(
110 | getApplicationContext());
111 | //判断是否高德地图可用的坐标
112 | boolean result = converter.isAMapDataAvailable(examplePoint.getLatitude(), examplePoint.getLongitude());
113 | if(result){
114 | tvCheckReult.setText("该坐标是高德地图可用坐标");
115 | } else {
116 | tvCheckReult.setText("该坐标不能用于高德地图");
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/Utils.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.amap.location.demo;
5 |
6 | import java.text.SimpleDateFormat;
7 | import java.util.Locale;
8 |
9 | import com.amap.api.location.AMapLocation;
10 |
11 | import android.text.TextUtils;
12 |
13 | /**
14 | * 辅助工具类
15 | * @创建时间: 2015年11月24日 上午11:46:50
16 | * @项目名称: AMapLocationDemo2.x
17 | * @author hongming.wang
18 | * @文件名称: Utils.java
19 | * @类型名称: Utils
20 | */
21 | public class Utils {
22 | /**
23 | * 开始定位
24 | */
25 | public final static int MSG_LOCATION_START = 0;
26 | /**
27 | * 定位完成
28 | */
29 | public final static int MSG_LOCATION_FINISH = 1;
30 | /**
31 | * 停止定位
32 | */
33 | public final static int MSG_LOCATION_STOP= 2;
34 |
35 | public final static String KEY_URL = "URL";
36 | public final static String URL_H5LOCATION = "file:///android_asset/location.html";
37 | /**
38 | * 根据定位结果返回定位信息的字符串
39 | * @param loc
40 | * @return
41 | */
42 | public synchronized static String getLocationStr(AMapLocation location){
43 | if(null == location){
44 | return null;
45 | }
46 | StringBuffer sb = new StringBuffer();
47 | //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
48 | if(location.getErrorCode() == 0){
49 | sb.append("定位成功" + "\n");
50 | sb.append("定位类型: " + location.getLocationType() + "\n");
51 | sb.append("经 度 : " + location.getLongitude() + "\n");
52 | sb.append("纬 度 : " + location.getLatitude() + "\n");
53 | sb.append("精 度 : " + location.getAccuracy() + "米" + "\n");
54 | sb.append("提供者 : " + location.getProvider() + "\n");
55 |
56 | sb.append("速 度 : " + location.getSpeed() + "米/秒" + "\n");
57 | sb.append("角 度 : " + location.getBearing() + "\n");
58 | // 获取当前提供定位服务的卫星个数
59 | sb.append("星 数 : " + location.getSatellites() + "\n");
60 | sb.append("国 家 : " + location.getCountry() + "\n");
61 | sb.append("省 : " + location.getProvince() + "\n");
62 | sb.append("市 : " + location.getCity() + "\n");
63 | sb.append("城市编码 : " + location.getCityCode() + "\n");
64 | sb.append("区 : " + location.getDistrict() + "\n");
65 | sb.append("区域 码 : " + location.getAdCode() + "\n");
66 | sb.append("地 址 : " + location.getAddress() + "\n");
67 | sb.append("兴趣点 : " + location.getPoiName() + "\n");
68 | //定位完成的时间
69 | sb.append("定位时间: " + formatUTC(location.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n");
70 | } else {
71 | //定位失败
72 | sb.append("定位失败" + "\n");
73 | sb.append("错误码:" + location.getErrorCode() + "\n");
74 | sb.append("错误信息:" + location.getErrorInfo() + "\n");
75 | sb.append("错误描述:" + location.getLocationDetail() + "\n");
76 | }
77 | //定位之后的回调时间
78 | sb.append("回调时间: " + formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n");
79 | return sb.toString();
80 | }
81 |
82 | private static SimpleDateFormat sdf = null;
83 | public synchronized static String formatUTC(long l, String strPattern) {
84 | if (TextUtils.isEmpty(strPattern)) {
85 | strPattern = "yyyy-MM-dd HH:mm:ss";
86 | }
87 | if (sdf == null) {
88 | try {
89 | sdf = new SimpleDateFormat(strPattern, Locale.CHINA);
90 | } catch (Throwable e) {
91 | }
92 | } else {
93 | sdf.applyPattern(strPattern);
94 | }
95 | return sdf == null ? "NULL" : sdf.format(l);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/eclipse/AMapLocationDemo/src/com/amap/location/demo/view/FeatureView.java:
--------------------------------------------------------------------------------
1 | package com.amap.location.demo.view;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.widget.FrameLayout;
6 | import android.widget.TextView;
7 |
8 | import com.amap.location.demo.R;
9 |
10 | public final class FeatureView extends FrameLayout {
11 |
12 | public FeatureView(Context context) {
13 | super(context);
14 |
15 | LayoutInflater layoutInflater = (LayoutInflater) context
16 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
17 | layoutInflater.inflate(R.layout.feature, this);
18 | }
19 |
20 | public synchronized void setTitleId(int titleId) {
21 | ((TextView) (findViewById(R.id.title))).setText(titleId);
22 | }
23 |
24 | public synchronized void setDescriptionId(int descriptionId) {
25 | ((TextView) (findViewById(R.id.description))).setText(descriptionId);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/eclipse/Readme.md:
--------------------------------------------------------------------------------
1 | #Eclipse工程
2 | 目录结构服务Eclipse工程目录结构,适合使用eclipse编译、运行
3 |
4 |
5 |
--------------------------------------------------------------------------------