listB = result.suggestionResultItems;
113 |
114 | StringBuffer buffer = new StringBuffer();
115 |
116 | for (PoiSearchResult.SearchResultItem item : listA) {
117 |
118 | buffer.append(item.city + "\n");
119 | buffer.append(item.name + "\n");
120 | buffer.append(item.address + "\n");
121 | buffer.append(item.longitude + "\n");
122 | buffer.append(item.latitude + "\n");
123 | }
124 |
125 | for (PoiSearchResult.SuggestionResultItem item : listB) {
126 | buffer.append(item.cityName + "\n");
127 | buffer.append(item.suggestionNum + "\n");
128 | }
129 |
130 |
131 | buffer.append("-------------------------------------------------------" + "\n");
132 |
133 | tv_result.setText(buffer.toString());
134 |
135 |
136 | }
137 |
138 | @Override
139 | public void onSearchFailure(String message) {
140 |
141 | tv_result.setText(message);
142 |
143 | }
144 | });
145 |
146 | poiKeywordSearch.startNearBySearch(30.21316, 120.214939, "", PoiSearchClient.DEFAULT_POI_TYPES.get(4), "杭州市", 0);
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_geo.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
20 |
21 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
36 |
37 |
44 |
45 |
52 |
53 |
54 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
17 |
18 |
19 |
25 |
26 |
27 |
33 |
34 |
35 |
41 |
42 |
43 |
49 |
50 |
51 |
57 |
58 |
59 |
65 |
66 |
67 |
73 |
74 |
80 |
81 |
82 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_location.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_map.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_poisearch.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
13 |
19 |
20 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
36 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GDDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/chen/gddemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chen.gddemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/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.0.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 |
25 | ext {
26 | GROUP = 'com.gezbox.map'
27 | VERSION_NAME = "1.0.0"
28 | POM_PACKAGING = "pom"
29 | POM_DESCRIPTION= "Gezbox Map"
30 |
31 | POM_URL="https://github.com/czhzero/AndroidMapSdk"
32 | POM_SCM_URL="https://github.com/czhzero/AndroidMapSdk"
33 | POM_SCM_CONNECTION="scm:git:https://github.com/czhzero/AndroidMapSdk.git"
34 | POM_SCM_DEV_CONNECTION="scm:git:git@github.com:czhzero/AndroidMapSdk.git"
35 |
36 | POM_LICENCE_NAME="The Apache Software License, Version 2.0"
37 | POM_LICENCE_URL="http://www.apache.org/licenses/LICENSE-2.0.txt"
38 | POM_LICENCE_DIST="repo"
39 |
40 | POM_DEVELOPER_ID="gezbox"
41 | POM_DEVELOPER_NAME="Gezbox, Inc."
42 | }
--------------------------------------------------------------------------------
/gradle-mvn-push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return VERSION_NAME.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getReleaseRepositoryUrl() {
25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
31 | : "https://oss.sonatype.org/content/repositories/snapshots/"
32 | }
33 |
34 | def getRepositoryUsername() {
35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
36 | }
37 |
38 | def getRepositoryPassword() {
39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
40 | }
41 |
42 | afterEvaluate { project ->
43 | uploadArchives {
44 | repositories {
45 | mavenDeployer {
46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
47 |
48 | pom.groupId = GROUP
49 | pom.artifactId = POM_ARTIFACT_ID
50 | pom.version = VERSION_NAME
51 |
52 | repository(url: getReleaseRepositoryUrl()) {
53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
54 | }
55 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
57 | }
58 |
59 | pom.project {
60 | name POM_NAME
61 | packaging POM_PACKAGING
62 | description POM_DESCRIPTION
63 | url POM_URL
64 |
65 | scm {
66 | url POM_SCM_URL
67 | connection POM_SCM_CONNECTION
68 | developerConnection POM_SCM_DEV_CONNECTION
69 | }
70 |
71 | licenses {
72 | license {
73 | name POM_LICENCE_NAME
74 | url POM_LICENCE_URL
75 | distribution POM_LICENCE_DIST
76 | }
77 | }
78 |
79 | developers {
80 | developer {
81 | id POM_DEVELOPER_ID
82 | name POM_DEVELOPER_NAME
83 | }
84 | }
85 | }
86 | }
87 | }
88 | }
89 |
90 | signing {
91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
92 | sign configurations.archives
93 | }
94 |
95 | task androidJavadocs(type: Javadoc) {
96 | source = android.sourceSets.main.java.srcDirs
97 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
98 | }
99 |
100 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
101 | classifier = 'javadoc'
102 | from androidJavadocs.destinationDir
103 | }
104 |
105 | task androidSourcesJar(type: Jar) {
106 | classifier = 'sources'
107 | from android.sourceSets.main.java.sourceFiles
108 | }
109 |
110 | artifacts {
111 | archives androidSourcesJar
112 | archives androidJavadocsJar
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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.10-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/libraries/android-library-map/.gitignore:
--------------------------------------------------------------------------------
1 | # general
2 | *~
3 | *.swp
4 | .DS_Store
5 |
6 | # java
7 | *.class
8 |
9 | # android
10 | .idea
11 | *.iml
12 | build
13 | local.properties
14 | .gradle
15 |
16 |
--------------------------------------------------------------------------------
/libraries/android-library-map/README.md:
--------------------------------------------------------------------------------
1 | 百度地图Api封装`
2 |
--------------------------------------------------------------------------------
/libraries/android-library-map/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply from: '../../gradle-mvn-push.gradle'
3 |
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion '23.0.1'
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile files('libs/AMap2DMap_2.9.0_AMapSearch_3.3.0_AMapLocation_2.6.0_20160628.jar')
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/libraries/android-library-map/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
19 |
20 | POM_ARTIFACT_ID=gezbox-map
21 | POM_NAME=Gezbox Map for Android
--------------------------------------------------------------------------------
/libraries/android-library-map/libs/AMap2DMap_2.9.0_AMapSearch_3.3.0_AMapLocation_2.6.0_20160628.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/libraries/android-library-map/libs/AMap2DMap_2.9.0_AMapSearch_3.3.0_AMapLocation_2.6.0_20160628.jar
--------------------------------------------------------------------------------
/libraries/android-library-map/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 /Users/liuyang/Library/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 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/geocoder/GeoCoderClient.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.geocoder;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.amap.api.services.core.LatLonPoint;
7 | import com.amap.api.services.geocoder.GeocodeAddress;
8 | import com.amap.api.services.geocoder.GeocodeQuery;
9 | import com.amap.api.services.geocoder.GeocodeResult;
10 | import com.amap.api.services.geocoder.GeocodeSearch;
11 | import com.amap.api.services.geocoder.RegeocodeQuery;
12 | import com.amap.api.services.geocoder.RegeocodeResult;
13 | import com.gezbox.map.utils.LogHelper;
14 |
15 | import java.util.ArrayList;
16 |
17 | /**
18 | * Created by chenzhaohua on 16/7/26.
19 | *
20 | * 地址解析与反地址解析类
21 | */
22 | public class GeoCoderClient implements GeocodeSearch.OnGeocodeSearchListener {
23 |
24 | private GeocodeSearch mGeocoderSearch;
25 | private GeoCoderListener mListener;
26 |
27 |
28 | public GeoCoderClient(Context context) {
29 | mGeocoderSearch = new GeocodeSearch(context.getApplicationContext());
30 | mGeocoderSearch.setOnGeocodeSearchListener(this);
31 | }
32 |
33 | /**
34 | * 设置搜索结果监听
35 | *
36 | * @param listener
37 | */
38 | public void setOnGeocodeSearchListener(GeoCoderListener listener) {
39 | mListener = listener;
40 | }
41 |
42 |
43 | /**
44 | * 地址解析
45 | *
46 | * @param keyword 地址
47 | * @param city 城市 (中文或者中文全拼,citycode,adcode)
48 | *
49 | */
50 | public void getLatlon(String keyword, String city) {
51 | LogHelper.d("GeoCoderClient getLatlon : " + "keyword = " + keyword + "city = " + city);
52 | GeocodeQuery query = new GeocodeQuery(keyword, city);
53 | mGeocoderSearch.getFromLocationNameAsyn(query);
54 | }
55 |
56 |
57 | /**
58 | * 逆地址解析
59 | *
60 | * @param lat
61 | * @param lon
62 | */
63 | public void getAddress(double lat, double lon) {
64 | LogHelper.d("GeoCoderClient getAddress : " + "lat = " + lat + "lon = " + lon);
65 | LatLonPoint lp = new LatLonPoint(lat, lon);
66 | // 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
67 | RegeocodeQuery query = new RegeocodeQuery(lp, 200, GeocodeSearch.AMAP);
68 | mGeocoderSearch.getFromLocationAsyn(query);
69 |
70 | }
71 |
72 | /**
73 | * 接受逆地址解析结果
74 | *
75 | * @param regeocodeResult
76 | * @param rCode 1000为正常
77 | */
78 | @Override
79 | public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int rCode) {
80 |
81 | if (regeocodeResult == null || mListener == null) {
82 | return;
83 | }
84 |
85 | LogHelper.d("GeoCoderClient onRegeocodeSearched : " + "\n" + regeocodeResult.toString());
86 |
87 | if (rCode != 1000) {
88 | mListener.onReGeoCoderFailure("逆地址解析失败");
89 | return;
90 | }
91 |
92 | if (regeocodeResult != null && regeocodeResult.getRegeocodeAddress() != null
93 | && regeocodeResult.getRegeocodeAddress().getFormatAddress() != null) {
94 |
95 | ReGeoCoderResult result = new ReGeoCoderResult();
96 | result.address = regeocodeResult.getRegeocodeAddress().getFormatAddress();
97 | result.buildding = regeocodeResult.getRegeocodeAddress().getBuilding();
98 | result.city = regeocodeResult.getRegeocodeAddress().getCity();
99 |
100 | mListener.onReGeoCoderSuccess(result);
101 |
102 | } else {
103 | mListener.onReGeoCoderFailure("未解析到结果");
104 | }
105 |
106 | }
107 |
108 | /**
109 | * 接受地址解析结果
110 | *
111 | * @param geocodeResult
112 | * @param rCode 1000为正常
113 | */
114 | @Override
115 | public void onGeocodeSearched(GeocodeResult geocodeResult, int rCode) {
116 |
117 | if (geocodeResult == null || mListener == null) {
118 | return;
119 | }
120 |
121 | LogHelper.d("GeoCoderClient onGeocodeSearched : " + "\n" + geocodeResult.toString());
122 |
123 |
124 | if (rCode != 1000) {
125 | mListener.onGeoCoderFailure("地址解析失败");
126 | return;
127 | }
128 |
129 |
130 | if (geocodeResult != null && geocodeResult.getGeocodeAddressList() != null
131 | && geocodeResult.getGeocodeAddressList().size() > 0) {
132 |
133 | GeoCoderResult result = new GeoCoderResult();
134 | result.geoList = new ArrayList<>();
135 |
136 | for (GeocodeAddress address : geocodeResult.getGeocodeAddressList()) {
137 | GeoCoderResult.GeoCoderItem item = new GeoCoderResult.GeoCoderItem();
138 | item.latitude = address.getLatLonPoint().getLatitude();
139 | item.longitude = address.getLatLonPoint().getLongitude();
140 | item.address = address.getFormatAddress();
141 | item.city = address.getCity();
142 | result.geoList.add(item);
143 | }
144 |
145 | mListener.onGeoCoderSuccess(result);
146 |
147 | } else {
148 | mListener.onGeoCoderFailure("未解析到结果");
149 | }
150 |
151 |
152 | }
153 |
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/geocoder/GeoCoderListener.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.geocoder;
2 |
3 | /**
4 | * Created by chenzhaohua on 16/7/26.
5 | *
6 | * 地址解析回调
7 | *
8 | */
9 | public interface GeoCoderListener {
10 |
11 | void onGeoCoderSuccess(GeoCoderResult result);
12 |
13 | void onGeoCoderFailure(String message);
14 |
15 | void onReGeoCoderSuccess(ReGeoCoderResult result);
16 |
17 | void onReGeoCoderFailure(String message);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/geocoder/GeoCoderResult.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.geocoder;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by chenzhaohua on 16/7/26.
7 | *
8 | * 地址解析结果
9 | */
10 | public class GeoCoderResult {
11 |
12 | public List geoList;
13 |
14 | public static class GeoCoderItem {
15 | public double latitude; //纬度
16 | public double longitude; //经度
17 | public String address; //地址
18 | public String city; //城市
19 | }
20 |
21 |
22 | @Override
23 | public String toString() {
24 |
25 | StringBuffer buffer = new StringBuffer();
26 |
27 | if (geoList == null || geoList.size() == 0) {
28 | return "";
29 | }
30 |
31 | for (GeoCoderResult.GeoCoderItem item : geoList) {
32 |
33 | if (item == null) {
34 | continue;
35 | }
36 |
37 | buffer.append(item.address + "\n");
38 | buffer.append(item.city + "\n");
39 | buffer.append(item.latitude + "\n");
40 | buffer.append(item.longitude + "\n");
41 | }
42 |
43 | return buffer.toString();
44 |
45 | }
46 |
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/geocoder/ReGeoCoderResult.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.geocoder;
2 |
3 |
4 | /**
5 | * Created by chenzhaohua on 16/7/26.
6 | *
7 | * 逆地址解析结果
8 | */
9 | public class ReGeoCoderResult {
10 |
11 | public String city; //城市
12 | public String address; //详细地址
13 | public String buildding; //建筑物
14 |
15 |
16 | @Override
17 | public String toString() {
18 |
19 | StringBuffer buffer = new StringBuffer();
20 |
21 | buffer.append(city + "\n");
22 | buffer.append(address + "\n");
23 | buffer.append(buildding + "\n");
24 |
25 | return buffer.toString();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/location/Location.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.location;
2 |
3 |
4 | /**
5 | * Created by chenzhaohua on 16/7/25.
6 | *
7 | * 定位结果类
8 | *
9 | */
10 | public class Location {
11 |
12 |
13 | private int type; //定位类型
14 | private double longitude; //经度
15 | private double latitude; //纬度
16 | private float accuracy; //精度
17 | private String provider; //提供者
18 |
19 | //仅GPS定位才会有
20 | private float speed; //速度
21 | private float bearing; //角度
22 | private int satellites; //卫星数目
23 |
24 | //仅网络定位才会有
25 | private String country; //国家
26 | private String province; //省份
27 | private String city; //市
28 | private String cityCode; //市编码
29 | private String district; //区
30 | private String adCode; //区编码
31 | private String address; //地址
32 | private String poiName; //兴趣点
33 |
34 | //状态信息
35 | private int errorCode; //错误码, 0 表示成功
36 | private String errorInfo; //错误信息
37 | private String errorDetail; //错误详情
38 |
39 |
40 |
41 | @Override
42 | public String toString() {
43 | return "Location{" +
44 | "type=" + type +
45 | ", longitude=" + longitude +
46 | ", latitude=" + latitude +
47 | ", accuracy=" + accuracy +
48 | ", provider='" + provider + '\'' +
49 | ", speed=" + speed +
50 | ", bearing=" + bearing +
51 | ", satellites=" + satellites +
52 | ", country='" + country + '\'' +
53 | ", province='" + province + '\'' +
54 | ", city='" + city + '\'' +
55 | ", cityCode='" + cityCode + '\'' +
56 | ", district='" + district + '\'' +
57 | ", adCode='" + adCode + '\'' +
58 | ", address='" + address + '\'' +
59 | ", poiName='" + poiName + '\'' +
60 | ", errorCode=" + errorCode +
61 | ", errorInfo=" + errorInfo +
62 | ", errorDetail=" + errorDetail +
63 | '}';
64 | }
65 |
66 | public String toResultString() {
67 |
68 | StringBuffer sb = new StringBuffer();
69 | //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
70 | if (getErrorCode() == 0) {
71 | sb.append("定位成功" + "\n");
72 | sb.append("定位类型: " + getLocationType() + "\n");
73 | sb.append("经 度 : " + getLongitude() + "\n");
74 | sb.append("纬 度 : " + getLatitude() + "\n");
75 | sb.append("精 度 : " + getAccuracy() + "米" + "\n");
76 | sb.append("提供者 : " + getProvider() + "\n");
77 |
78 | if (getProvider().equalsIgnoreCase(
79 | android.location.LocationManager.GPS_PROVIDER)) {
80 | // 以下信息只有提供者是GPS时才会有
81 | sb.append("速 度 : " + getSpeed() + "米/秒" + "\n");
82 | sb.append("角 度 : " + getBearing() + "\n");
83 | // 获取当前提供定位服务的卫星个数
84 | sb.append("星 数 : "
85 | + getSatellites() + "\n");
86 | } else {
87 | // 提供者是GPS时是没有以下信息的
88 | sb.append("国 家 : " + getCountry() + "\n");
89 | sb.append("省 : " + getProvince() + "\n");
90 | sb.append("市 : " + getCity() + "\n");
91 | sb.append("城市编码 : " + getCityCode() + "\n");
92 | sb.append("区 : " + getDistrict() + "\n");
93 | sb.append("区域 码 : " + getAdCode() + "\n");
94 | sb.append("地 址 : " + getAddress() + "\n");
95 | sb.append("兴趣点 : " + getPoiName() + "\n");
96 | }
97 | } else {
98 | //定位失败
99 | sb.append("定位失败" + "\n");
100 | sb.append("错误码:" + getErrorCode() + "\n");
101 | sb.append("错误信息:" + getErrorInfo() + "\n");
102 | sb.append("错误描述:" + getErrorDetail() + "\n");
103 | }
104 | return sb.toString();
105 | }
106 |
107 |
108 | public int getLocationType() {
109 | return type;
110 | }
111 |
112 | public void setLocationType(int ype) {
113 | this.type = ype;
114 | }
115 |
116 | public double getLongitude() {
117 | return longitude;
118 | }
119 |
120 | public void setLongitude(double longitude) {
121 | this.longitude = longitude;
122 | }
123 |
124 | public double getLatitude() {
125 | return latitude;
126 | }
127 |
128 | public void setLatitude(double latitude) {
129 | this.latitude = latitude;
130 | }
131 |
132 | public float getAccuracy() {
133 | return accuracy;
134 | }
135 |
136 | public void setAccuracy(float accuracy) {
137 | this.accuracy = accuracy;
138 | }
139 |
140 | public String getProvider() {
141 | return provider;
142 | }
143 |
144 | public void setProvider(String provider) {
145 | this.provider = provider;
146 | }
147 |
148 | public float getSpeed() {
149 | return speed;
150 | }
151 |
152 | public void setSpeed(float speed) {
153 | this.speed = speed;
154 | }
155 |
156 | public float getBearing() {
157 | return bearing;
158 | }
159 |
160 | public void setBearing(float bearing) {
161 | this.bearing = bearing;
162 | }
163 |
164 | public int getSatellites() {
165 | return satellites;
166 | }
167 |
168 | public void setSatellites(int satellites) {
169 | this.satellites = satellites;
170 | }
171 |
172 | public String getCountry() {
173 | return country;
174 | }
175 |
176 | public void setCountry(String country) {
177 | this.country = country;
178 | }
179 |
180 | public String getProvince() {
181 | return province;
182 | }
183 |
184 | public void setProvince(String province) {
185 | this.province = province;
186 | }
187 |
188 | public String getCity() {
189 | return city;
190 | }
191 |
192 | public void setCity(String city) {
193 | this.city = city;
194 | }
195 |
196 | public String getCityCode() {
197 | return cityCode;
198 | }
199 |
200 | public void setCityCode(String cityCode) {
201 | this.cityCode = cityCode;
202 | }
203 |
204 | public String getDistrict() {
205 | return district;
206 | }
207 |
208 | public void setDistrict(String district) {
209 | this.district = district;
210 | }
211 |
212 | public String getAdCode() {
213 | return adCode;
214 | }
215 |
216 | public void setAdCode(String adCode) {
217 | this.adCode = adCode;
218 | }
219 |
220 | public String getAddress() {
221 | return address;
222 | }
223 |
224 | public void setAddress(String address) {
225 | this.address = address;
226 | }
227 |
228 | public String getPoiName() {
229 | return poiName;
230 | }
231 |
232 | public void setPoiName(String poiName) {
233 | this.poiName = poiName;
234 | }
235 |
236 | public int getErrorCode() {
237 | return errorCode;
238 | }
239 |
240 | public void setErrorCode(int errorCode) {
241 | this.errorCode = errorCode;
242 | }
243 |
244 | public String getErrorInfo() {
245 | return errorInfo;
246 | }
247 |
248 | public void setErrorInfo(String errorInfo) {
249 | this.errorInfo = errorInfo;
250 | }
251 |
252 | public String getErrorDetail() {
253 | return errorDetail;
254 | }
255 |
256 | public void setErrorDetail(String errorDetail) {
257 | this.errorDetail = errorDetail;
258 | }
259 | }
260 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/location/LocationClient.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.location;
2 |
3 | import android.content.Context;
4 |
5 | import com.amap.api.location.AMapLocation;
6 | import com.amap.api.location.AMapLocationClient;
7 | import com.amap.api.location.AMapLocationClientOption;
8 | import com.amap.api.location.AMapLocationListener;
9 | import com.gezbox.map.utils.LogHelper;
10 |
11 |
12 | /**
13 | * Created by chenzhaohua on 16/7/25.
14 | *
15 | * 高德定位服务
16 | */
17 | public class LocationClient implements AMapLocationListener {
18 |
19 | private Context mContext;
20 | private LocationListener mListener;
21 | private AMapLocationClient mLocationClient;
22 | private AMapLocationClientOption mLocationOption;
23 |
24 |
25 | public LocationClient(Context context) {
26 | mContext = context.getApplicationContext();
27 | }
28 |
29 | /**
30 | * 设置监听
31 | *
32 | * @param listener
33 | */
34 | public void setLocationListener(LocationListener listener) {
35 | mListener = listener;
36 | }
37 |
38 |
39 | /**
40 | * 启动定位服务
41 | */
42 | public void startLocate() {
43 | LogHelper.d("LocationClient startLocate : once");
44 | mLocationOption = getDefaultOption().setOnceLocation(true);
45 | startLocate(mLocationOption);
46 | }
47 |
48 |
49 | /**
50 | * 启动定位服务
51 | */
52 | public void startLocate(int span) {
53 | LogHelper.d("LocationClient startLocate : " + span);
54 | mLocationOption = getDefaultOption().setInterval(span);
55 | startLocate(mLocationOption);
56 | }
57 |
58 |
59 | /**
60 | * 停止定位
61 | */
62 | public void stopLocate() {
63 | LogHelper.d("LocationClient stopLocate");
64 | if (mLocationClient != null) {
65 | mLocationClient.stopLocation();
66 | }
67 | }
68 |
69 | /**
70 | * 释放定位对象
71 | */
72 | public void releaseLocate() {
73 | LogHelper.d("LocationClient releaseLocate");
74 | if (mLocationClient != null) {
75 | mLocationClient.stopLocation();
76 | mLocationClient.onDestroy();
77 | mLocationClient = null;
78 | mLocationClient = null;
79 | }
80 | }
81 |
82 |
83 | /**
84 | * 启动定位服务
85 | */
86 | private void startLocate(AMapLocationClientOption option) {
87 | if (mLocationClient == null) {
88 | mLocationClient = new AMapLocationClient(mContext);
89 | mLocationClient.setLocationListener(this);
90 | }
91 |
92 | mLocationClient.setLocationOption(option);
93 |
94 | if (!mLocationClient.isStarted()) {
95 | mLocationClient.startLocation();
96 | }
97 | }
98 |
99 |
100 | /**
101 | * 获取default option
102 | *
103 | * @return
104 | */
105 | private AMapLocationClientOption getDefaultOption() {
106 | AMapLocationClientOption option = new AMapLocationClientOption();
107 | //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
108 | option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
109 | option.setNeedAddress(true); //设置是否需要显示地址信息
110 | option.setLocationCacheEnable(true); //设置是否开启缓存
111 | return option;
112 | }
113 |
114 |
115 | @Override
116 | public void onLocationChanged(AMapLocation aMapLocation) {
117 |
118 | if (aMapLocation == null || mListener == null) {
119 | return;
120 | }
121 |
122 | LogHelper.d("LocationClient onLocationChanged : " + aMapLocation.toString());
123 |
124 |
125 | Location location = new Location();
126 |
127 | //basic
128 | location.setLocationType(aMapLocation.getLocationType());
129 | location.setLongitude(aMapLocation.getLongitude());
130 | location.setLatitude(aMapLocation.getLatitude());
131 | location.setAccuracy(aMapLocation.getAccuracy());
132 | location.setProvider(aMapLocation.getProvider());
133 |
134 | //error code
135 | location.setErrorCode(aMapLocation.getErrorCode());
136 | location.setErrorDetail(aMapLocation.getLocationDetail());
137 | location.setErrorInfo(aMapLocation.getErrorInfo());
138 |
139 |
140 | //gps
141 | location.setSpeed(aMapLocation.getSpeed());
142 | location.setBearing(aMapLocation.getBearing());
143 | location.setSatellites(aMapLocation.getSatellites());
144 |
145 |
146 | //net
147 | location.setCountry(aMapLocation.getCountry());
148 | location.setProvince(aMapLocation.getProvince());
149 | location.setCity(aMapLocation.getCity());
150 | location.setCityCode(aMapLocation.getCityCode());
151 | location.setDistrict(aMapLocation.getDistrict());
152 | location.setAdCode(aMapLocation.getAdCode());
153 | location.setAddress(aMapLocation.getAddress());
154 | location.setPoiName(aMapLocation.getPoiName());
155 |
156 |
157 | if (location.getErrorCode() == 0) {
158 | mListener.onLocateSuccess(location);
159 | } else {
160 | mListener.onLocateFailure(location);
161 | }
162 |
163 |
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/location/LocationListener.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.location;
2 |
3 | /**
4 | * Created by chenzhaohua on 16/7/25.
5 | * 定位结果回调接口
6 | */
7 | public interface LocationListener {
8 |
9 | void onLocateSuccess(Location location);
10 |
11 | void onLocateFailure(Location location);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/overlay/CircleLayer.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.overlay;
2 |
3 | import com.amap.api.maps2d.AMap;
4 | import com.amap.api.maps2d.model.CircleOptions;
5 | import com.amap.api.maps2d.model.LatLng;
6 | import com.gezbox.map.utils.LogHelper;
7 | import com.gezbox.map.view.CustomMapView;
8 |
9 | /**
10 | * Created by chenzhaohua on 16/7/27.
11 | *
12 | * 圆形图层类,用于在地图画圆
13 | */
14 | public class CircleLayer {
15 |
16 | private AMap mAmap;
17 |
18 |
19 | public CircleLayer(CustomMapView mapView) {
20 | mAmap = mapView.getMap();
21 | }
22 |
23 |
24 | public void addCircle(double lat, double lon, double radius, int strokeColor,
25 | int fillColor, float strokeWidth) {
26 |
27 | LogHelper.d("CircleLayer addCircle : " + "lat = " + lat + "lon = " + lon + "radius ="
28 | + radius + "strokeColor = " + strokeColor + "fillColor = " + fillColor
29 | + "strokeWidth = " + strokeWidth);
30 |
31 | CircleOptions circleOptions = new CircleOptions();
32 | circleOptions.center(new LatLng(lat, lon));
33 | circleOptions.radius(radius);
34 | circleOptions.strokeColor(strokeColor);
35 | circleOptions.fillColor(fillColor);
36 | circleOptions.strokeWidth(strokeWidth);
37 | mAmap.addCircle(circleOptions);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/overlay/MarkerLayer.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.overlay;
2 |
3 | import android.text.TextUtils;
4 | import android.view.View;
5 |
6 | import com.amap.api.maps2d.AMap;
7 | import com.amap.api.maps2d.model.BitmapDescriptor;
8 | import com.amap.api.maps2d.model.BitmapDescriptorFactory;
9 | import com.amap.api.maps2d.model.LatLng;
10 | import com.amap.api.maps2d.model.Marker;
11 | import com.amap.api.maps2d.model.MarkerOptions;
12 | import com.gezbox.map.utils.LogHelper;
13 | import com.gezbox.map.view.CustomMapView;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * Created by chenzhaohua on 16/7/27.
19 | *
20 | * 地图Marker类,用于在地图上添加地址的marker
21 | *
22 | */
23 | public class MarkerLayer implements AMap.OnMarkerClickListener, AMap.OnInfoWindowClickListener,
24 | AMap.OnMarkerDragListener, AMap.OnMapLoadedListener, AMap.InfoWindowAdapter {
25 |
26 | private AMap mAmap;
27 | private int mFocusMarkerDrawableId;
28 | private int mCommonMarkerDrawableId;
29 |
30 |
31 | public MarkerLayer(CustomMapView mapView) {
32 | mAmap = mapView.getMap();
33 | mAmap.setOnMarkerDragListener(this); // 设置marker可拖拽事件监听器
34 | mAmap.setOnMapLoadedListener(this); // 设置amap加载成功事件监听器
35 | mAmap.setOnMarkerClickListener(this); // 设置点击marker事件监听器
36 | mAmap.setOnInfoWindowClickListener(this); // 设置点击infoWindow事件监听器
37 | mAmap.setInfoWindowAdapter(this); // 设置自定义InfoWindow样式
38 | }
39 |
40 |
41 | /**
42 | * 添加marker
43 | *
44 | * @param lat
45 | * @param lon
46 | */
47 | public void addMarker(double lat, double lon) {
48 | addMarker(lat, lon, null);
49 | }
50 |
51 |
52 | /**
53 | * 添加marker
54 | *
55 | * @param lat
56 | * @param lon
57 | * @param title
58 | */
59 | public void addMarker(double lat, double lon, String title) {
60 |
61 | LogHelper.d("MarkerLayer addMarker : " + "lat = " + lat + "lon = " + lon + "title ="
62 | + title);
63 |
64 |
65 | MarkerOptions options = new MarkerOptions();
66 | options.position(new LatLng(lat, lon));
67 |
68 | if (!TextUtils.isEmpty(title)) {
69 | options.title(title);
70 | }
71 |
72 | options.icon(getCommonMarkerIcon());
73 | options.draggable(true);
74 | mAmap.addMarker(options);
75 |
76 | }
77 |
78 | /**
79 | * 设置某个marker为焦点
80 | *
81 | * @param lat
82 | * @param lon
83 | */
84 | public void focusMarker(double lat, double lon) {
85 | List markers = mAmap.getMapScreenMarkers();
86 |
87 | if (markers == null || markers.size() == 0) {
88 | return;
89 | }
90 |
91 | //自己当前位置的marker不做任何处理
92 | if (isMyLocation(lat, lon)) {
93 | return;
94 | }
95 |
96 | for (Marker marker : markers) {
97 | LatLng latLng = marker.getPosition();
98 |
99 | //自己当前位置的marker不做任何处理
100 | if (isMyLocation(latLng.latitude, latLng.longitude)) {
101 | continue;
102 | }
103 |
104 | //选中的marker,改变icon,弹出info
105 | if (latLng.latitude == lat && latLng.longitude == lon) {
106 | marker.setIcon(getFocusMarkerIcon());
107 | marker.showInfoWindow();
108 | } else {
109 | marker.setIcon(getCommonMarkerIcon());
110 | }
111 | }
112 | }
113 |
114 |
115 | /**
116 | * 设置marker图片
117 | *
118 | * @param focusId 正选中marker时的图片
119 | * @param commonId 未选中marker时的图片
120 | */
121 | public void setMarkerDrawble(int focusId, int commonId) {
122 | mFocusMarkerDrawableId = focusId;
123 | mCommonMarkerDrawableId = commonId;
124 | }
125 |
126 |
127 | /**
128 | * 清除所有marker
129 | */
130 | public void clearAllMarker() {
131 | mAmap.clear();
132 | }
133 |
134 |
135 | @Override
136 | public void onInfoWindowClick(Marker marker) {
137 | LogHelper.d("onInfoWindowClick");
138 |
139 | }
140 |
141 | @Override
142 | public void onMapLoaded() {
143 | LogHelper.d("onMapLoaded");
144 |
145 | }
146 |
147 | @Override
148 | public boolean onMarkerClick(Marker marker) {
149 | LogHelper.d("onMarkerClick");
150 | //TODO 增加自定义事件
151 | focusMarker(marker.getPosition().latitude, marker.getPosition().longitude);
152 | return false;
153 | }
154 |
155 | @Override
156 | public void onMarkerDragStart(Marker marker) {
157 | LogHelper.d("onMarkerDragStart");
158 | }
159 |
160 | @Override
161 | public void onMarkerDrag(Marker marker) {
162 | LogHelper.d("onMarkerDrag");
163 | }
164 |
165 | @Override
166 | public void onMarkerDragEnd(Marker marker) {
167 | LogHelper.d("onMarkerDragEnd");
168 |
169 | }
170 |
171 | @Override
172 | public View getInfoWindow(Marker marker) {
173 | LogHelper.d("getInfoWindow");
174 | //TODO 增加自定义布局
175 | return null;
176 | }
177 |
178 | @Override
179 | public View getInfoContents(Marker marker) {
180 | LogHelper.d("getInfoContents");
181 | return null;
182 | }
183 |
184 |
185 | /**
186 | * 判断是否为当前所在位置
187 | *
188 | * @param lat
189 | * @param lon
190 | * @return
191 | */
192 | private boolean isMyLocation(double lat, double lon) {
193 | if (mAmap.getMyLocation().getLatitude() == lat && mAmap.getMyLocation().getLongitude() == lon) {
194 | return true;
195 | } else {
196 | return false;
197 | }
198 | }
199 |
200 | /**
201 | * 获取focus状态的Icon
202 | *
203 | * @return
204 | */
205 | private BitmapDescriptor getFocusMarkerIcon() {
206 | if (mFocusMarkerDrawableId > 0) {
207 | return BitmapDescriptorFactory.fromResource(mFocusMarkerDrawableId);
208 | } else {
209 | return BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED);
210 | }
211 | }
212 |
213 | /**
214 | * 获取common状态的Icon
215 | *
216 | * @return
217 | */
218 | private BitmapDescriptor getCommonMarkerIcon() {
219 | if (mCommonMarkerDrawableId > 0) {
220 | return BitmapDescriptorFactory.fromResource(mCommonMarkerDrawableId);
221 | } else {
222 | return BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE);
223 | }
224 | }
225 |
226 |
227 | }
228 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/overlay/PolyLineLayer.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.overlay;
2 |
3 | import android.graphics.Color;
4 | import com.amap.api.maps2d.AMap;
5 | import com.amap.api.maps2d.model.LatLng;
6 | import com.amap.api.maps2d.model.PolylineOptions;
7 | import com.gezbox.map.utils.LogHelper;
8 | import com.gezbox.map.view.CustomMapView;
9 |
10 | /**
11 | * Created by chenzhaohua on 16/7/27.
12 | *
13 | * 绘制直线类,用于在地图上绘制直线
14 | *
15 | */
16 | public class PolyLineLayer {
17 |
18 | private AMap mAMap;
19 |
20 | private final static int COMMON_LINE = 0;
21 | private final static int DOTTED_LINE = 1;
22 | private final static int GEODESIC_LINE = 2;
23 |
24 |
25 | private final static int DEFAULT_COLOR = Color.RED;
26 | private final static int DEFAULT_WIDTH = 2;
27 | private final static int DEFAULT_STYLE = COMMON_LINE;
28 |
29 |
30 | public PolyLineLayer(CustomMapView mapView) {
31 | mAMap = mapView.getMap();
32 |
33 | }
34 |
35 |
36 | public void addLine(double startLat, double startLon, double endLat, double endLon) {
37 |
38 | LogHelper.d("PolyLineLayer addLine : " + "startLat = " + startLat + "startLon = "
39 | + startLon + "endLat = " + endLat + "endLon = " + endLon);
40 |
41 | PolylineOptions options = new PolylineOptions();
42 | options.add(new LatLng(startLat, startLon), new LatLng(endLat, endLon));
43 | options.color(DEFAULT_COLOR);
44 | options.width(DEFAULT_WIDTH);
45 | mAMap.addPolyline(options);
46 | mAMap.invalidate();
47 | }
48 |
49 |
50 | //TODO 可以增加自定义属性,同时点也可以多个, 若要修改已经绘制成功的线条
51 | //TODO 则需要改变PolyLine对象, 建议在上层应用中,不直接使用高德包的内容
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/poisearch/PoiSearchClient.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.poisearch;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 |
6 |
7 | import com.amap.api.services.core.LatLonPoint;
8 | import com.amap.api.services.core.PoiItem;
9 | import com.amap.api.services.core.SuggestionCity;
10 | import com.amap.api.services.poisearch.PoiResult;
11 | import com.amap.api.services.poisearch.PoiSearch;
12 | import com.gezbox.map.utils.LogHelper;
13 |
14 | import java.util.ArrayList;
15 | import java.util.Arrays;
16 | import java.util.List;
17 |
18 | /**
19 | * Created by chenzhaohua on 16/7/25.
20 | *
21 | * POI检索类
22 | * 1.普通检索
23 | * 2.附近检索
24 | *
25 | */
26 | public class PoiSearchClient implements com.amap.api.services.poisearch.PoiSearch.OnPoiSearchListener {
27 |
28 |
29 | public static final List DEFAULT_POI_TYPES = Arrays.asList("汽车服务", "汽车销售",
30 | "汽车维修", "摩托车服务", "餐饮服务", "购物服务", "生活服务", "体育休闲服务", "医疗保健服务",
31 | "住宿服务", "风景名胜", "商务住宅", "政府机构及社会团体", "科教文化服务", "交通设施服务",
32 | "金融保险服务", "公司企业", "道路附属设施", "地名地址信息", "公共设施");
33 |
34 |
35 | private PoiSearch.Query mQuery;
36 | private PoiSearch mPoiSearch;
37 | private Context mContext;
38 | private PoiSearchListener mListener;
39 |
40 |
41 | public PoiSearchClient(Context context) {
42 | mContext = context.getApplicationContext();
43 | }
44 |
45 |
46 | public void setPoiSearchListener(PoiSearchListener listener) {
47 | mListener = listener;
48 | }
49 |
50 |
51 | /**
52 | * 开始POI搜索
53 | *
54 | * @param keyWord 搜索关键字 (key 与 type 必须填一个)
55 | * @param type poi搜索类型 (不设置,默认返回“餐饮服务”、“商务住宅”、“生活服务”)
56 | * @param city poi搜索区域(空字符串代表全国)
57 | * @param page 返回第N页数据
58 | */
59 | public void startSearch(String keyWord, String type, String city, int page) {
60 |
61 |
62 | LogHelper.d("PoiSearchClient startSearch : " + "keyWord = " + keyWord + "type = " + type + "city ="
63 | + city + "page = " + page);
64 |
65 | //key 与 type 必须填一个
66 | if (TextUtils.isEmpty(keyWord) && TextUtils.isEmpty(type)) {
67 | return;
68 | }
69 |
70 | if (city == null) {
71 | city = "";
72 | }
73 |
74 | if (page < 0) {
75 | page = 0;
76 | }
77 |
78 | mQuery = new PoiSearch.Query(keyWord, type, city);
79 | mQuery.setPageSize(10); //Max Page
80 | mQuery.setPageNum(page);
81 | mQuery.setCityLimit(true);
82 |
83 | mPoiSearch = new PoiSearch(mContext, mQuery);
84 | mPoiSearch.setOnPoiSearchListener(this);
85 | mPoiSearch.searchPOIAsyn();
86 | }
87 |
88 | /**
89 | * 开始POI附近地址搜索
90 | *
91 | * @param lon 经度
92 | * @param lat 纬度
93 | * @param keyWord 搜索关键字 (key 与 type 必须填一个)
94 | * @param type poi搜索类型 (不设置,默认返回“餐饮服务”、“商务住宅”、“生活服务”)
95 | * @param city poi搜索区域(空字符串代表全国)
96 | * @param page 返回第N页数据
97 | */
98 | public void startNearBySearch(double lat, double lon, String keyWord, String type, String city, int page) {
99 |
100 | LogHelper.d("PoiSearchClient startNearBySearch : " + "lat = " + lat + "lon = " + lon + "keyWord = "
101 | + keyWord + "type = " + type + "city =" + city + "page = " + page);
102 |
103 | //key 与 type 必须填一个
104 | if (TextUtils.isEmpty(keyWord) && TextUtils.isEmpty(type)) {
105 | return;
106 | }
107 |
108 | if (city == null) {
109 | city = "";
110 | }
111 |
112 | if (page < 0) {
113 | page = 0;
114 | }
115 |
116 | mQuery = new PoiSearch.Query(keyWord, type, city);
117 | mQuery.setPageSize(10); //Max Page
118 | mQuery.setPageNum(page);
119 | mQuery.setCityLimit(true);
120 |
121 | mPoiSearch = new PoiSearch(mContext, mQuery);
122 | mPoiSearch.setOnPoiSearchListener(this);
123 | LatLonPoint lp = new LatLonPoint(lat, lon);
124 | mPoiSearch.setBound(new PoiSearch.SearchBound(lp, 5000, true)); //搜索附近5000米
125 | mPoiSearch.searchPOIAsyn();
126 |
127 | }
128 |
129 |
130 |
131 |
132 | @Override
133 | public void onPoiSearched(PoiResult result, int rCode) {
134 |
135 | if (result == null || mListener == null) {
136 | return;
137 | }
138 |
139 | LogHelper.d("PoiSearchClient onPoiSearched : " + result.toString());
140 |
141 | if (rCode != 1000) {
142 | mListener.onSearchFailure("" + rCode);
143 | return;
144 | }
145 |
146 |
147 | if (result != null && result.getQuery() != null) {// 搜索poi的结果
148 |
149 | // 是否
150 | if (result.getQuery().equals(mQuery)) {
151 |
152 | PoiSearchResult poiResult = new PoiSearchResult();
153 |
154 | poiResult.searchResultItems = new ArrayList<>();
155 | poiResult.suggestionResultItems = new ArrayList<>();
156 |
157 |
158 | List poiItems = result.getPois();
159 | List suggestionCities = result.getSearchSuggestionCitys();
160 |
161 |
162 | if ((poiItems == null || poiItems.size() <= 0)
163 | && (suggestionCities == null || suggestionCities.size() <= 0)) {
164 | mListener.onSearchFailure("未搜索到结果");
165 | return;
166 | }
167 |
168 | for(PoiItem index : poiItems) {
169 | PoiSearchResult.SearchResultItem item = new PoiSearchResult.SearchResultItem();
170 | item.address = index.getSnippet();
171 | item.city = index.getCityName();
172 | item.name = index.getTitle();
173 | item.latitude = index.getLatLonPoint().getLatitude();
174 | item.longitude = index.getLatLonPoint().getLongitude();
175 | poiResult.searchResultItems.add(item);
176 | }
177 |
178 |
179 | for(SuggestionCity index:suggestionCities) {
180 | PoiSearchResult.SuggestionResultItem item = new PoiSearchResult.SuggestionResultItem();
181 | item.cityName = index.getCityName();
182 | item.suggestionNum = index.getSuggestionNum();
183 | poiResult.suggestionResultItems.add(item);
184 | }
185 |
186 | mListener.onSearchSuccess(poiResult);
187 |
188 |
189 | }
190 | } else {
191 | mListener.onSearchFailure("未搜索到结果");
192 | }
193 | }
194 |
195 | @Override
196 | public void onPoiItemSearched(PoiItem poiItem, int i) {
197 |
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/poisearch/PoiSearchListener.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.poisearch;
2 |
3 | /**
4 | * Created by chenzhaohua on 16/7/26.
5 | * Poi检索回调接口
6 | */
7 | public interface PoiSearchListener {
8 |
9 | void onSearchSuccess(PoiSearchResult result);
10 | void onSearchFailure(String message);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/poisearch/PoiSearchResult.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.poisearch;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by chenzhaohua on 16/7/26.
7 | * Poi检索结果类
8 | */
9 | public class PoiSearchResult {
10 |
11 | public List searchResultItems; //搜索结果
12 | public List suggestionResultItems; //搜索不到后的推荐结果
13 |
14 | public static class SearchResultItem {
15 | public String name;
16 | public String city;
17 | public String address;
18 | public double latitude;
19 | public double longitude;
20 | }
21 |
22 | public static class SuggestionResultItem {
23 | public String cityName; //城市名称
24 | public int suggestionNum; //推荐数目 d
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/route/DriverRouteLayer.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.route;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.amap.api.maps2d.AMap;
6 | import com.amap.api.maps2d.AMapUtils;
7 | import com.amap.api.maps2d.CameraUpdateFactory;
8 | import com.amap.api.maps2d.model.BitmapDescriptor;
9 | import com.amap.api.maps2d.model.BitmapDescriptorFactory;
10 | import com.amap.api.maps2d.model.LatLng;
11 | import com.amap.api.maps2d.model.LatLngBounds;
12 | import com.amap.api.maps2d.model.Marker;
13 | import com.amap.api.maps2d.model.MarkerOptions;
14 | import com.amap.api.maps2d.model.Polyline;
15 | import com.amap.api.maps2d.model.PolylineOptions;
16 | import com.amap.api.services.core.LatLonPoint;
17 | import com.amap.api.services.route.DrivePath;
18 | import com.amap.api.services.route.DriveStep;
19 | import com.amap.api.services.route.TMC;
20 | import com.gezbox.map.R;
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * Created by chenzhaohua on 16/7/27.
26 | *
27 | * 这个类有时间需要重构,需结合步行路线
28 | *
29 | */
30 | public class DriverRouteLayer {
31 |
32 | private AMap mAMap;
33 | private LatLng mStartPoint;
34 | private LatLng mEndPoint;
35 | private Marker mStartMarker;
36 | private Marker mEndMarker;
37 |
38 | private DrivePath drivePath;
39 | private List mLatLngsOfPath; //路径上的点
40 | private List mThroughPointList; //路径上的点
41 | private List mThroughPointMarkerList = new ArrayList<>(); //路径上的marker
42 | private List mTmcs; //路径拥堵情况
43 |
44 | private boolean throughPointMarkerVisible = true;
45 |
46 | private PolylineOptions mPolylineOptions;
47 | private boolean isColorfulline = true;
48 | private float mWidth = 15;
49 | protected boolean nodeIconVisible = true;
50 |
51 | protected List stationMarkers = new ArrayList<>();
52 | protected List allPolyLines = new ArrayList<>();
53 |
54 |
55 | public void setIsColorfulline(boolean iscolorfulline) {
56 | this.isColorfulline = iscolorfulline;
57 | }
58 |
59 | /**
60 | * 根据给定的参数,构造一个导航路线图层类对象。
61 | * @param amap 地图对象。
62 | * @param path 导航路线规划方案。
63 | * @param start 起点
64 | * @param end 终点
65 | * @param throughPointList 途径点
66 | */
67 | public DriverRouteLayer(AMap amap, DrivePath path,
68 | LatLonPoint start, LatLonPoint end, List throughPointList) {
69 | mAMap = amap;
70 | drivePath = path;
71 | mStartPoint = new LatLng(start.getLatitude(),start.getLongitude());
72 | mEndPoint = new LatLng(end.getLatitude(),end.getLongitude());
73 | mThroughPointList = throughPointList;
74 | }
75 |
76 | /**
77 | * 设置路线宽度
78 | * @param width 路线宽度,取值范围:大于0
79 | */
80 | public void setRouteWidth(float width) {
81 | mWidth = width;
82 | }
83 |
84 | /**
85 | * 添加路线添加到地图上显示。
86 | */
87 | public void addToMap() {
88 |
89 | initPolylineOptions();
90 |
91 | try {
92 |
93 | if (mAMap == null) {
94 | return;
95 | }
96 |
97 | if (mWidth == 0 || drivePath == null) {
98 | return;
99 | }
100 |
101 | mLatLngsOfPath = new ArrayList<>();
102 |
103 | mTmcs = new ArrayList<>();
104 |
105 | List drivePaths = drivePath.getSteps();
106 |
107 | mPolylineOptions.add(mStartPoint);
108 |
109 | for (DriveStep step : drivePaths) {
110 | List latlonPoints = step.getPolyline();
111 | List tmclist = step.getTMCs();
112 | mTmcs.addAll(tmclist);
113 | addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0)));
114 | for (LatLonPoint latlonpoint : latlonPoints) {
115 | mPolylineOptions.add(convertToLatLng(latlonpoint));
116 | mLatLngsOfPath.add(convertToLatLng(latlonpoint));
117 | }
118 | }
119 |
120 | mPolylineOptions.add(mEndPoint);
121 |
122 | if (mStartMarker != null) {
123 | mStartMarker.remove();
124 | mStartMarker = null;
125 | }
126 | if (mEndMarker != null) {
127 | mEndMarker.remove();
128 | mEndMarker = null;
129 | }
130 | addStartAndEndMarker();
131 | addThroughPointMarker();
132 | if (isColorfulline && mTmcs.size()>0 ) {
133 | colorWayUpdate(mTmcs);
134 | }else {
135 | showPolyline();
136 | }
137 |
138 | } catch (Throwable e) {
139 | e.printStackTrace();
140 | }
141 | }
142 |
143 | private void addStartAndEndMarker() {
144 | mStartMarker = mAMap.addMarker((new MarkerOptions())
145 | .position(mStartPoint).icon(getStartBitmapDescriptor())
146 | .title("\u8D77\u70B9"));
147 | mEndMarker = mAMap.addMarker((new MarkerOptions()).position(mEndPoint)
148 | .icon(getEndBitmapDescriptor()).title("\u7EC8\u70B9"));
149 | }
150 |
151 | /**
152 | * 初始化线段属性
153 | */
154 | private void initPolylineOptions() {
155 |
156 | mPolylineOptions = null;
157 | mPolylineOptions = new PolylineOptions();
158 | mPolylineOptions.color(getDriveColor()).width(mWidth);
159 | }
160 |
161 |
162 |
163 | private void showPolyline() {
164 | addPolyLine(mPolylineOptions);
165 | }
166 |
167 |
168 |
169 |
170 | private void colorWayUpdate(List tmcSection) {
171 | if (mAMap == null) {
172 | return;
173 | }
174 | if (mLatLngsOfPath == null || mLatLngsOfPath.size() <= 0) {
175 | return;
176 | }
177 | if (tmcSection == null || tmcSection.size() <= 0) {
178 | return;
179 | }
180 | int j = 0;
181 | LatLng startLatLng = mLatLngsOfPath.get(0);
182 | LatLng endLatLng = null;
183 | double segmentTotalDistance = 0;
184 | TMC segmentTrafficStatus;
185 | List tempList = new ArrayList();
186 | //画出起点到规划路径之间的连线
187 | addPolyLine(new PolylineOptions().add(mStartPoint, startLatLng)
188 | .setDottedLine(true));
189 | //终点和规划路径之间连线
190 | addPolyLine(new PolylineOptions().add(mLatLngsOfPath.get(mLatLngsOfPath.size() - 1),
191 | mEndPoint).setDottedLine(true));
192 | for (int i = 0; i < mLatLngsOfPath.size() && j < tmcSection.size(); i++) {
193 | segmentTrafficStatus = tmcSection.get(j);
194 | endLatLng = mLatLngsOfPath.get(i);
195 | double distanceBetweenTwoPosition = AMapUtils.calculateLineDistance(startLatLng, endLatLng);
196 | segmentTotalDistance = segmentTotalDistance + distanceBetweenTwoPosition;
197 | if (segmentTotalDistance > segmentTrafficStatus.getDistance() + 1) {
198 | double toSegDis = distanceBetweenTwoPosition - (segmentTotalDistance - segmentTrafficStatus.getDistance());
199 | LatLng middleLatLng = getPointForDis(startLatLng, endLatLng, toSegDis);
200 | tempList.add(middleLatLng);
201 | startLatLng = middleLatLng;
202 | i--;
203 | } else {
204 | tempList.add(endLatLng);
205 | startLatLng = endLatLng;
206 | }
207 | if (segmentTotalDistance >= segmentTrafficStatus.getDistance() || i == mLatLngsOfPath.size() - 1) {
208 | if (j == tmcSection.size() - 1 && i < mLatLngsOfPath.size() - 1) {
209 | for (i++; i < mLatLngsOfPath.size(); i++) {
210 | LatLng lastLatLng = mLatLngsOfPath.get(i);
211 | tempList.add(lastLatLng);
212 | }
213 | }
214 | j++;
215 | if (segmentTrafficStatus.getStatus().equals("畅通")) {
216 | addPolyLine((new PolylineOptions()).addAll(tempList)
217 | .width(mWidth).color(Color.GREEN));
218 | } else if (segmentTrafficStatus.getStatus().equals("缓行")) {
219 | addPolyLine((new PolylineOptions()).addAll(tempList)
220 | .width(mWidth).color(Color.YELLOW));
221 | } else if (segmentTrafficStatus.getStatus().equals("拥堵")) {
222 | addPolyLine((new PolylineOptions()).addAll(tempList)
223 | .width(mWidth).color(Color.RED));
224 | } else if (segmentTrafficStatus.getStatus().equals("严重拥堵")) {
225 | addPolyLine((new PolylineOptions()).addAll(tempList)
226 | .width(mWidth).color(Color.parseColor("#990033")));
227 | } else {
228 | addPolyLine((new PolylineOptions()).addAll(tempList)
229 | .width(mWidth).color(Color.parseColor("#537edc")));
230 | }
231 | tempList.clear();
232 | tempList.add(startLatLng);
233 | segmentTotalDistance = 0;
234 | }
235 | if (i == mLatLngsOfPath.size() - 1) {
236 | addPolyLine(new PolylineOptions().add(endLatLng, mEndPoint)
237 | .setDottedLine(true));
238 | }
239 | }
240 | }
241 |
242 | private LatLng convertToLatLng(LatLonPoint point) {
243 | return new LatLng(point.getLatitude(),point.getLongitude());
244 | }
245 |
246 | /**
247 | * @param driveStep
248 | * @param latLng
249 | */
250 | private void addDrivingStationMarkers(DriveStep driveStep, LatLng latLng) {
251 | MarkerOptions options = new MarkerOptions().position(latLng)
252 | .title("\u65B9\u5411:" + driveStep.getAction()
253 | + "\n\u9053\u8DEF:" + driveStep.getRoad())
254 | .snippet(driveStep.getInstruction()).visible(nodeIconVisible)
255 | .anchor(0.5f, 0.5f).icon(getDriveBitmapDescriptor());
256 | if(options == null) {
257 | return;
258 | }
259 | Marker marker = mAMap.addMarker(options);
260 | if(marker != null) {
261 | stationMarkers.add(marker);
262 | }
263 | }
264 |
265 | private LatLngBounds getLatLngBounds() {
266 | LatLngBounds.Builder b = LatLngBounds.builder();
267 | b.include(new LatLng(mStartPoint.latitude, mStartPoint.longitude));
268 | b.include(new LatLng(mEndPoint.latitude, mEndPoint.longitude));
269 | if (this.mThroughPointList != null && this.mThroughPointList.size() > 0) {
270 | for (int i = 0; i < this.mThroughPointList.size(); i++) {
271 | b.include(new LatLng(
272 | this.mThroughPointList.get(i).getLatitude(),
273 | this.mThroughPointList.get(i).getLongitude()));
274 | }
275 | }
276 | return b.build();
277 | }
278 |
279 |
280 | private void addThroughPointMarker() {
281 | if (this.mThroughPointList != null && this.mThroughPointList.size() > 0) {
282 | LatLonPoint latLonPoint = null;
283 | for (int i = 0; i < this.mThroughPointList.size(); i++) {
284 | latLonPoint = this.mThroughPointList.get(i);
285 | if (latLonPoint != null) {
286 | mThroughPointMarkerList.add(mAMap.addMarker(new MarkerOptions()
287 | .position(new LatLng(latLonPoint.getLatitude(),latLonPoint.getLongitude()))
288 | .visible(throughPointMarkerVisible)
289 | .icon(getThroughPointBitDes())
290 | .title("\u9014\u7ECF\u70B9")));
291 | }
292 | }
293 | }
294 | }
295 |
296 | private BitmapDescriptor getThroughPointBitDes() {
297 | return BitmapDescriptorFactory.fromResource(R.drawable.car);
298 | }
299 |
300 | private BitmapDescriptor getDriveBitmapDescriptor() {
301 | return BitmapDescriptorFactory.fromResource(R.drawable.car);
302 | }
303 |
304 | /**
305 | * 给起点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
306 | * @return 更换的Marker图片。
307 | */
308 | private BitmapDescriptor getStartBitmapDescriptor() {
309 | return BitmapDescriptorFactory.fromResource(R.drawable.start);
310 | }
311 |
312 | /**
313 | * 给终点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
314 | *
315 | * @return 更换的Marker图片。
316 | */
317 | private BitmapDescriptor getEndBitmapDescriptor() {
318 | return BitmapDescriptorFactory.fromResource(R.drawable.end);
319 | }
320 |
321 | private void addPolyLine(PolylineOptions options) {
322 | if(options == null) {
323 | return;
324 | }
325 | Polyline polyline = mAMap.addPolyline(options);
326 | if(polyline != null) {
327 | allPolyLines.add(polyline);
328 | }
329 | }
330 |
331 | private int getDriveColor() {
332 | return Color.parseColor("#537edc");
333 | }
334 |
335 | private LatLng getPointForDis(LatLng sPt, LatLng ePt, double dis) {
336 | double lSegLength = AMapUtils.calculateLineDistance(sPt, ePt);
337 | double preResult = dis / lSegLength;
338 | return new LatLng((ePt.latitude - sPt.latitude) * preResult + sPt.latitude, (ePt.longitude - sPt.longitude) * preResult + sPt.longitude);
339 | }
340 |
341 | public void setThroughPointIconVisibility(boolean visible) {
342 | try {
343 | throughPointMarkerVisible = visible;
344 | if (this.mThroughPointMarkerList != null
345 | && this.mThroughPointMarkerList.size() > 0) {
346 | for (int i = 0; i < this.mThroughPointMarkerList.size(); i++) {
347 | this.mThroughPointMarkerList.get(i).setVisible(visible);
348 | }
349 | }
350 | } catch (Throwable e) {
351 | e.printStackTrace();
352 | }
353 | }
354 |
355 | /**
356 | * 移动镜头到当前的视角。
357 | * @since V2.1.0
358 | */
359 | public void zoomToSpan() {
360 | if (mStartPoint != null) {
361 | if (mAMap == null)
362 | return;
363 | try {
364 | LatLngBounds bounds = getLatLngBounds();
365 | mAMap.animateCamera(CameraUpdateFactory
366 | .newLatLngBounds(bounds, 50));
367 | } catch (Throwable e) {
368 | e.printStackTrace();
369 | }
370 | }
371 | }
372 |
373 |
374 |
375 | /**
376 | * 路段节点图标控制显示接口。
377 | * @param visible true为显示节点图标,false为不显示。
378 | * @since V2.3.1
379 | */
380 | public void setNodeIconVisibility(boolean visible) {
381 | try {
382 | nodeIconVisible = visible;
383 | if (this.stationMarkers != null && this.stationMarkers.size() > 0) {
384 | for (int i = 0; i < this.stationMarkers.size(); i++) {
385 | this.stationMarkers.get(i).setVisible(visible);
386 | }
387 | }
388 | } catch (Throwable e) {
389 | e.printStackTrace();
390 | }
391 | }
392 |
393 |
394 |
395 | /**
396 | * 去掉DriveLineOverlay上的线段和标记。
397 | */
398 | public void removeFromMap() {
399 | try {
400 | if (mStartMarker != null) {
401 | mStartMarker.remove();
402 |
403 | }
404 | if (mEndMarker != null) {
405 | mEndMarker.remove();
406 | }
407 | for (Marker marker : stationMarkers) {
408 | marker.remove();
409 | }
410 | for (Polyline line : allPolyLines) {
411 | line.remove();
412 | }
413 | if (this.mThroughPointMarkerList != null
414 | && this.mThroughPointMarkerList.size() > 0) {
415 | for (int i = 0; i < this.mThroughPointMarkerList.size(); i++) {
416 | this.mThroughPointMarkerList.get(i).remove();
417 | }
418 | this.mThroughPointMarkerList.clear();
419 | }
420 | } catch (Throwable e) {
421 | e.printStackTrace();
422 | }
423 | }
424 |
425 | }
426 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/route/RouteSearchClient.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.route;
2 |
3 | import android.content.Context;
4 |
5 | import com.amap.api.maps2d.AMap;
6 | import com.amap.api.services.core.LatLonPoint;
7 | import com.amap.api.services.route.BusRouteResult;
8 | import com.amap.api.services.route.DrivePath;
9 | import com.amap.api.services.route.DriveRouteResult;
10 | import com.amap.api.services.route.RouteSearch;
11 | import com.amap.api.services.route.WalkRouteResult;
12 | import com.gezbox.map.utils.LogHelper;
13 | import com.gezbox.map.view.CustomMapView;
14 |
15 | /**
16 | * Created by chenzhaohua on 16/7/27.
17 | *
18 | * 路径规划类
19 | *
20 | */
21 | public class RouteSearchClient implements RouteSearch.OnRouteSearchListener {
22 |
23 |
24 | private final static int TYPE_BUS = 1;
25 | private final static int TYPE_DRIVE = 2;
26 | private final static int TYPE_WALK = 3;
27 |
28 | private Context mContext;
29 | private RouteSearch mRouteSearch;
30 | private AMap mAmap;
31 |
32 |
33 | public RouteSearchClient(CustomMapView mapView) {
34 | mContext = mapView.getContext().getApplicationContext();
35 | mAmap = mapView.getMap();
36 | mRouteSearch = new RouteSearch(mContext);
37 | mRouteSearch.setRouteSearchListener(this);
38 | }
39 |
40 |
41 | /**
42 | * 搜索公交线路
43 | *
44 | * @param startLat
45 | * @param startLon
46 | * @param endLat
47 | * @param endLon
48 | * @param city
49 | */
50 | public void searchBusRoute(double startLat, double startLon,
51 | double endLat, double endLon, String city) {
52 | LogHelper.d("RouteSearchClient searchBusRoute : " + "startLat = " + startLat + "startLon = "
53 | + startLon + "endLat =" + endLat + "endLon = " + endLon + "city = " + city);
54 | RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(
55 | new LatLonPoint(startLat, startLon), new LatLonPoint(endLat, endLon));
56 | startSearchRoute(fromAndTo, TYPE_BUS, RouteSearch.BusDefault, city);
57 | }
58 |
59 | /**
60 | * 搜索驾车线路
61 | *
62 | * @param startLat
63 | * @param startLon
64 | * @param endLat
65 | * @param endLon
66 | */
67 | public void searchDriveRoute(double startLat, double startLon, double endLat, double endLon) {
68 | LogHelper.d("RouteSearchClient searchDriveRoute : " + "startLat = " + startLat + "startLon = "
69 | + startLon + "endLat =" + endLat + "endLon = " + endLon);
70 | RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(
71 | new LatLonPoint(startLat, startLon), new LatLonPoint(endLat, endLon));
72 | startSearchRoute(fromAndTo, TYPE_DRIVE, RouteSearch.DrivingDefault, null);
73 | }
74 |
75 |
76 | /**
77 | * 搜索步行线路
78 | * @param startLat
79 | * @param startLon
80 | * @param endLat
81 | * @param endLon
82 | */
83 | public void searchWalkRoute(double startLat, double startLon, double endLat, double endLon) {
84 | LogHelper.d("RouteSearchClient searchWalkRoute : " + "startLat = " + startLat + "startLon = "
85 | + startLon + "endLat =" + endLat + "endLon = " + endLon);
86 | RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(
87 | new LatLonPoint(startLat, startLon), new LatLonPoint(endLat, endLon));
88 | startSearchRoute(fromAndTo, TYPE_WALK, RouteSearch.WalkDefault, null);
89 | }
90 |
91 |
92 | private void startSearchRoute(RouteSearch.FromAndTo fromAndTo, int routeType, int mode, String city) {
93 |
94 | switch (routeType) {
95 |
96 | case TYPE_BUS:
97 | //第一个参数表示路径规划的起点和终点
98 | //第二个参数表示公交查询模式
99 | //第三个参数表示公交查询城市区号
100 | //第四个参数表示是否计算夜班车, 0表示不计算
101 | RouteSearch.BusRouteQuery query = new RouteSearch.BusRouteQuery(fromAndTo, mode,
102 | city, 0);
103 | mRouteSearch.calculateBusRouteAsyn(query);
104 |
105 | break;
106 | case TYPE_DRIVE:
107 | //第一个参数表示路径规划的起点和终点
108 | //第二个参数表示驾车模式
109 | //第三个参数表示途经点
110 | //第四个参数表示避让区域
111 | //第五个参数表示避让道路
112 | RouteSearch.DriveRouteQuery query2 = new RouteSearch.DriveRouteQuery(fromAndTo,
113 | mode, null, null, "");
114 | mRouteSearch.calculateDriveRouteAsyn(query2);
115 | break;
116 | case TYPE_WALK:
117 | RouteSearch.WalkRouteQuery query3 = new RouteSearch.WalkRouteQuery(fromAndTo, mode);
118 | mRouteSearch.calculateWalkRouteAsyn(query3);
119 | break;
120 |
121 | }
122 |
123 |
124 | }
125 |
126 |
127 | @Override
128 | public void onBusRouteSearched(BusRouteResult busRouteResult, int errorCode) {
129 | //TODO 等待增加回调接口处理,暂不处理
130 | }
131 |
132 | @Override
133 | public void onDriveRouteSearched(DriveRouteResult driveRouteResult, int errorCode) {
134 |
135 | mAmap.clear();
136 |
137 | if (errorCode != 1000) {
138 | return;
139 | }
140 |
141 | if(driveRouteResult!=null && driveRouteResult.getPaths()!=null && driveRouteResult.getPaths().size()>0) {
142 |
143 | final DrivePath drivePath = driveRouteResult.getPaths().get(0);
144 | DriverRouteLayer layer = new DriverRouteLayer(
145 | mAmap, drivePath,
146 | driveRouteResult.getStartPos(),
147 | driveRouteResult.getTargetPos(),null);
148 | layer.removeFromMap();
149 | layer.addToMap();
150 | layer.zoomToSpan();
151 | }
152 |
153 | }
154 |
155 | @Override
156 | public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int errorCode) {
157 | //TODO 等待增加回调接口处理,暂不处理
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/setting/MapSettings.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.setting;
2 |
3 | import com.amap.api.maps2d.AMap;
4 | import com.amap.api.maps2d.CameraUpdateFactory;
5 | import com.amap.api.maps2d.UiSettings;
6 | import com.amap.api.maps2d.model.BitmapDescriptorFactory;
7 | import com.amap.api.maps2d.model.MyLocationStyle;
8 | import com.gezbox.map.view.CustomMapView;
9 |
10 | /**
11 | * Created by chenzhaohua on 16/7/27.
12 | * 地图基本信息设置类
13 | */
14 | public class MapSettings {
15 |
16 | private UiSettings mUiSettings;
17 | private AMap mAmap;
18 |
19 | public MapSettings(CustomMapView mapView) {
20 |
21 | mAmap = mapView.getMap();
22 | mUiSettings = mAmap.getUiSettings();
23 | }
24 |
25 |
26 | /**
27 | * 自定义小蓝点的属性(默认属性)
28 | */
29 | public void setMyLocationStyle() {
30 | //TODO 根据设计师需求设置
31 | }
32 |
33 |
34 | /**
35 | * 自定义小蓝点的属性
36 | *
37 | * @param drawableId 设置小蓝点的图标
38 | * @param strokeColor 设置圆形的边框颜色
39 | * @param radiusFillColor 设置圆形的填充颜色
40 | * @param strokeWidth 设置圆形的边框粗细
41 | */
42 | public void setMyLocationStyle(int drawableId, int strokeColor, int radiusFillColor, float strokeWidth) {
43 |
44 | MyLocationStyle myLocationStyle = new MyLocationStyle();
45 | myLocationStyle.myLocationIcon(BitmapDescriptorFactory
46 | .fromResource(drawableId));
47 | myLocationStyle.strokeColor(strokeColor);
48 | myLocationStyle.radiusFillColor(radiusFillColor);
49 | // myLocationStyle.anchor(int,int)
50 | myLocationStyle.strokeWidth(strokeWidth);
51 | mAmap.setMyLocationStyle(myLocationStyle);
52 | }
53 |
54 |
55 |
56 | /**
57 | * 设置地图默认的定位按钮是否显示
58 | *
59 | * @param enabled
60 | */
61 | public void setMyLocationButtonEnabled(boolean enabled) {
62 | mUiSettings.setMyLocationButtonEnabled(enabled);
63 | }
64 |
65 |
66 | /**
67 | * 设置地图默认的比例尺是否显示
68 | *
69 | * @param enabled
70 | */
71 | public void setScaleControlsEnabled(boolean enabled) {
72 | mUiSettings.setScaleControlsEnabled(enabled);
73 | }
74 |
75 | /**
76 | * 设置地图默认的缩放按钮是否显示
77 | *
78 | * @param enabled
79 | */
80 | public void setZoomControlsEnabled(boolean enabled) {
81 | mUiSettings.setZoomControlsEnabled(enabled);
82 | }
83 |
84 |
85 | /**
86 | * 设置地图默认的指南针是否显示
87 | *
88 | * @param enabled
89 | */
90 | public void setCompassEnabled(boolean enabled) {
91 | mUiSettings.setCompassEnabled(enabled);
92 | }
93 |
94 |
95 | /**
96 | * 设置地图是否可以手势滑动
97 | *
98 | * @param enabled
99 | */
100 | public void setScrollGesturesEnabled(boolean enabled) {
101 | mUiSettings.setScrollGesturesEnabled(enabled);
102 | }
103 |
104 | /**
105 | * 设置地图是否可以手势缩放大小
106 | *
107 | * @param enabled
108 | */
109 | public void setZoomGesturesEnabled(boolean enabled) {
110 | mUiSettings.setZoomGesturesEnabled(enabled);
111 | }
112 |
113 | /**
114 | * 调整地图尺寸比例
115 | * @param value
116 | */
117 | public void zoomTo(float value) {
118 | mAmap.moveCamera(CameraUpdateFactory.zoomTo(value));
119 | }
120 |
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/utils/LogHelper.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.utils;
2 |
3 | /**
4 | * Created by chenzhaohua on 16/7/25.
5 | * 日志打印
6 | *
7 | */
8 | public class LogHelper {
9 |
10 | private static final String DEFAULT_TAG = "map";
11 | private static final boolean DEBUG = true;
12 |
13 | public static void d(String tag, String msg) {
14 | if (DEBUG) {
15 | android.util.Log.d(tag, msg);
16 | }
17 | }
18 |
19 | public static void e(String tag, String msg) {
20 | if (DEBUG) {
21 | android.util.Log.e(tag, msg);
22 | }
23 | }
24 |
25 | public static void d(String msg) {
26 | if (DEBUG) {
27 | d(DEFAULT_TAG, msg);
28 | }
29 | }
30 |
31 | public static void e(String msg) {
32 | if (DEBUG) {
33 | e(DEFAULT_TAG, msg);
34 | }
35 | }
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/java/com/gezbox/map/view/CustomMapView.java:
--------------------------------------------------------------------------------
1 | package com.gezbox.map.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import com.amap.api.location.AMapLocation;
6 | import com.amap.api.location.AMapLocationClient;
7 | import com.amap.api.location.AMapLocationClientOption;
8 | import com.amap.api.location.AMapLocationListener;
9 | import com.amap.api.maps2d.AMap;
10 | import com.amap.api.maps2d.AMapOptions;
11 | import com.amap.api.maps2d.LocationSource;
12 | import com.amap.api.maps2d.MapView;
13 |
14 | /**
15 | * Created by chenzhaohua on 16/7/26.
16 | *
17 | * 使用CustomMapView过程注意事项:
18 | * 1.必须在Activity或者Fragment的生命周期中,依次调用onCreate, onResume, onPauseAndRelease,
19 | * onSaveInstanceState, onDestroy方法。
20 | *
21 | */
22 | public class CustomMapView extends MapView implements AMapLocationListener, LocationSource {
23 |
24 | private Context mContext;
25 | private AMap mAmap;
26 | private OnLocationChangedListener mListener;
27 | private AMapLocationClient mlocationClient;
28 | private AMapLocationClientOption mLocationOption;
29 |
30 | public CustomMapView(Context context) {
31 | super(context);
32 | init(context);
33 | }
34 |
35 | public CustomMapView(Context context, AttributeSet attributeSet) {
36 | super(context, attributeSet);
37 | init(context);
38 | }
39 |
40 | public CustomMapView(Context context, AttributeSet attributeSet, int i) {
41 | super(context, attributeSet, i);
42 | init(context);
43 | }
44 |
45 | @Deprecated
46 | public CustomMapView(Context context, AMapOptions aMapOptions) {
47 | super(context, aMapOptions);
48 | init(context);
49 | }
50 |
51 |
52 |
53 | private void init(Context context) {
54 | mContext = context.getApplicationContext();
55 | mAmap = getMap();
56 | }
57 |
58 |
59 |
60 | /**
61 | * onPause时,同时释放location资源
62 | */
63 | public void onPauseAndRelease() {
64 | onPause();
65 | deactivate();
66 | }
67 |
68 |
69 | /**
70 | * 设置是否可触发定位并显示定位层
71 | *
72 | * @param enabled
73 | */
74 | public void setMyLocationEnabled(boolean enabled) {
75 | mAmap.setLocationSource(this); //设置定位监听
76 | mAmap.setMyLocationEnabled(enabled);
77 | }
78 |
79 |
80 | /**
81 | * 定位成功后的回调
82 | * @param aMapLocation
83 | */
84 | @Override
85 | public void onLocationChanged(AMapLocation aMapLocation) {
86 |
87 | if (mListener != null && aMapLocation != null) {
88 | if (aMapLocation != null
89 | && aMapLocation.getErrorCode() == 0) {
90 | mListener.onLocationChanged(aMapLocation); //显示系统小蓝点
91 | }
92 | }
93 |
94 | }
95 |
96 |
97 | /**
98 | * 激活定位
99 | */
100 | @Override
101 | public void activate(OnLocationChangedListener onLocationChangedListener) {
102 |
103 | mListener = onLocationChangedListener;
104 | if (mlocationClient == null) {
105 | mlocationClient = new AMapLocationClient(mContext);
106 | mLocationOption = new AMapLocationClientOption();
107 | //设置定位监听
108 | mlocationClient.setLocationListener(this);
109 | //设置为高精度定位模式
110 | mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
111 | //设置定位参数
112 | mlocationClient.setLocationOption(mLocationOption);
113 |
114 | mlocationClient.startLocation();
115 | }
116 |
117 | }
118 |
119 |
120 |
121 | /**
122 | * 停止定位
123 | */
124 | @Override
125 | public void deactivate() {
126 | mListener = null;
127 | if (mlocationClient != null) {
128 | mlocationClient.stopLocation();
129 | mlocationClient.onDestroy();
130 | }
131 | mlocationClient = null;
132 | }
133 |
134 |
135 |
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/res/drawable-xhdpi/bus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/libraries/android-library-map/src/main/res/drawable-xhdpi/bus.png
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/res/drawable-xhdpi/car.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/libraries/android-library-map/src/main/res/drawable-xhdpi/car.png
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/res/drawable-xhdpi/end.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/libraries/android-library-map/src/main/res/drawable-xhdpi/end.png
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/res/drawable-xhdpi/man.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/libraries/android-library-map/src/main/res/drawable-xhdpi/man.png
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/res/drawable-xhdpi/start.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/czhzero/AndroidMapSdk/0f9b625cee5cd52e2c5f69435637899c9582769c/libraries/android-library-map/src/main/res/drawable-xhdpi/start.png
--------------------------------------------------------------------------------
/libraries/android-library-map/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | baidumap
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | include ':libraries:android-library-map'
--------------------------------------------------------------------------------