diff --git a/.gitignore b/.gitignore index 7f7b9c3..aceaaf2 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,9 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk /target/ + +.idea/ +.gradle/ +build/ +local.properties +*.iml diff --git a/README.md b/README.md index 358268a..a8dc8c0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,30 @@ -coordtransform 坐标转换 +CoordTransform 坐标转换 --- -提供百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具模块 -(参考wandergis的python版coordtransform的Java版实现) -其他版本实现 ---- -* [java版本](https://github.com/geosmart/coordtransform) -* [javascript版本](https://github.com/wandergis/coordtransform) -* [python版本](https://github.com/wandergis/coordtransform) +[](https://jitpack.io/#ipcjs/coordtransform) + +[wandergis/coordtransform](https://github.com/wandergis/coordtransform)的Java版。 +提供百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具模块。 + +**注意**:CoordinateTransformUtil的方法的输入输出参数都为`(lng, lat)`,和Android一般的`(lat, lng)`正好相反,使用时要注意一下。 + +## 国内外判断 + +黄色为原版的国内区域,蓝色和红色为修改后的国内区域 + + + +## 测试 + +- [CoordinateConverterTest.java](/src/test/java/me/demo/util/geo/test/CoordinateConverterTest.java):将坐标转换后生成[Web版百度](http://lbsyun.baidu.com/index.php?title=uri/api/web)的Url,点开即可查看转换是否偏移 + +## 其他版本实现 + +- JavaScript版:[wandergis/coordtransform](https://github.com/wandergis/coordtransform) +- Python版:[wandergis/coordTransform_py](https://github.com/wandergis/coordTransform_py) +- Java版:[geosmart/coordtransform](https://github.com/geosmart/coordtransform) +- Dart/Flutter版:[ipcjs/coordtransform_dart](https://github.com/ipcjs/coordtransform_dart) + +## 参考资料 +- [Coordtransform 的使用文档](http://wandergis.com/coordtransform/) diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..d39ffe3 --- /dev/null +++ b/build.gradle @@ -0,0 +1,82 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.2.2' + } +} + +allprojects { + repositories { + google() + maven { url 'https://jitpack.io' } + mavenCentral() + } +} + +ext { + compileSdkVersion = 33 + minSdkVersion = 19 + targetSdkVersion = 33 +} + +apply plugin: 'com.android.application' + +android { + compileSdk rootProject.compileSdkVersion + + defaultConfig { + applicationId "com.github.ipcjs.coordtransform" + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + manifestPlaceholders = [ + BAIDU_MAP_KEY : "rM8VXLKBO7K9F69vdAyNc1Mr9H8p9wma", + GOOGLE_MAP_KEY: "xx", + ] + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + signingConfigs { + // your debug keystore + debug { + storeFile file("debug.keystore") + } + } + + sourceSets { + main { + jniLibs.srcDir 'libs' + } + } + lintOptions { + abortOnError false + } +} + +dependencies { + implementation project(':library') + implementation 'com.github.ipcjs.baidu-map-sdk:g01:g01_3.0.5' + + testImplementation "junit:junit:4.13.2" + androidTestImplementation "androidx.test.ext:junit:1.1.5" + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "androidx.appcompat:appcompat:1.3.1" +} \ No newline at end of file diff --git a/debug.keystore b/debug.keystore new file mode 100644 index 0000000..aa6b9e7 Binary files /dev/null and b/debug.keystore differ diff --git a/doc/is_in_china.jpg b/doc/is_in_china.jpg new file mode 100644 index 0000000..e122ed2 Binary files /dev/null and b/doc/is_in_china.jpg differ diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..0068720 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,15 @@ +## For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +#Thu Jun 13 10:57:14 CST 2024 +android.enableJetifier=true +android.useAndroidX=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..905ec45 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Nov 22 14:58:10 CST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.4-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/library/.gitignore @@ -0,0 +1 @@ +/build diff --git a/library/build.gradle b/library/build.gradle new file mode 100644 index 0000000..1b19556 --- /dev/null +++ b/library/build.gradle @@ -0,0 +1,9 @@ +apply plugin: 'java-library' +apply plugin: 'maven' + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) +} + +sourceCompatibility = "1.8" +targetCompatibility = "1.8" diff --git a/library/src/main/java/com/github/ipcjs/coordtransform/CoordinateTransformUtil.java b/library/src/main/java/com/github/ipcjs/coordtransform/CoordinateTransformUtil.java new file mode 100644 index 0000000..a8dc416 --- /dev/null +++ b/library/src/main/java/com/github/ipcjs/coordtransform/CoordinateTransformUtil.java @@ -0,0 +1,260 @@ +package com.github.ipcjs.coordtransform; + +/** + * 百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具 + *
+ * 参考wandergis/coordtransform实现的Java版本
+ * @author geosmart
+ */
+public class CoordinateTransformUtil {
+
+ // China region - raw data
+ public static final Rectangle[] REGION = {
+ new Rectangle(79.446200, 49.220400, 96.330000, 42.889900),
+ new Rectangle(109.687200, 54.141500, 135.000200, 39.374200),
+ new Rectangle(73.124600, 42.889900, 124.143255, 29.529700),
+ new Rectangle(82.968400, 29.529700, 97.035200, 26.718600),
+ new Rectangle(97.025300, 29.529700, 124.367395, 20.414096),
+ new Rectangle(107.975793, 20.414096, 111.744104, 17.871542),
+ };
+
+ // China excluded region - raw data
+ public static final Rectangle[] EXCLUDE = {
+ new Rectangle(119.921265, 25.398623, 122.497559, 21.785006),
+ new Rectangle(101.865200, 22.284000, 106.665000, 20.098800),
+ new Rectangle(106.452500, 21.542200, 108.051000, 20.487800),
+ new Rectangle(109.032300, 55.817500, 119.127000, 50.325700),
+ new Rectangle(127.456800, 55.817500, 137.022700, 49.557400),
+ new Rectangle(131.266200, 44.892200, 137.022700, 42.569200),
+ new Rectangle(73.124600, 35.398637, 77.948114, 29.529700),
+ };
+
+ // China excluded region 2, HongKong etc.
+ public static final Rectangle[] EXCLUDE_REGION_2 = {
+ new Rectangle(114.505238, 22.138258, 113.845000, 22.428903),
+ new Rectangle(113.97000, 22.507833, 114.450000, 22.428903),
+ };
+
+ private static double X_PI = 3.14159265358979324 * 3000.0 / 180.0;
+
+ // π
+ private static double PI = 3.1415926535897932384626;
+
+ // 长半轴
+ private static double A = 6378245.0;
+
+ // 扁率
+ private static double EE = 0.00669342162296594323;
+
+ private static boolean isInChina(double lng, double lat) {
+ return isInChina(lng, lat, true);
+ }
+
+ private static boolean isInChina(double lng, double lat, boolean excludeRegion2) {
+ for (Rectangle region : REGION) {
+ if (region.contain(lng, lat)) {
+ for (Rectangle exclude : EXCLUDE) {
+ if (exclude.contain(lng, lat)) {
+ return false;
+ }
+ }
+ if (excludeRegion2) {
+ for (Rectangle exclude : EXCLUDE_REGION_2) {
+ if (exclude.contain(lng, lat)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * WGS84转GCJ02(火星坐标系) (判断了中国范围)
+ * @param lng WGS84坐标系的经度
+ * @param lat WGS84坐标系的纬度
+ * @return 火星坐标数组
+ */
+ public static double[] wgs84ToGcj02(double lng, double lat) {
+ if (!isInChina(lng, lat)) {
+ return new double[]{lng, lat};
+ }
+ return wgs84ToGcj02Raw(lng, lat);
+ }
+
+ /**
+ * GCJ02(火星坐标系)转WGS84 (判断了中国范围)
+ * @param lng 火星坐标系的经度
+ * @param lat 火星坐标系纬度
+ * @return WGS84坐标数组
+ */
+ public static double[] gcj02ToWgs84(double lng, double lat) {
+ if (!isInChina(lng, lat)) {
+ return new double[]{lng, lat};
+ }
+ return gcj02ToWgs84Raw(lng, lat);
+ }
+
+ /**
+ * 百度坐标系(BD-09)转WGS坐标 (判断了中国范围)
+ * @param lng 百度坐标纬度
+ * @param lat 百度坐标经度
+ * @return WGS84坐标数组
+ */
+ public static double[] bd09ToWgs84(double lng, double lat) {
+ if (!isInChina(lng, lat, false)) {
+ return new double[]{lng, lat};
+ }
+ return bd09ToWgs84Raw(lng, lat);
+ }
+
+ /**
+ * WGS坐标转百度坐标系(BD-09) (判断了中国范围)
+ * @param lng WGS84坐标系的经度
+ * @param lat WGS84坐标系的纬度
+ * @return 百度坐标数组
+ */
+ public static double[] wgs84ToBd09(double lng, double lat) {
+ if (!isInChina(lng, lat, false)) {
+ return new double[]{lng, lat};
+ }
+ return wgs84ToBd09Raw(lng, lat);
+ }
+
+ /**
+ * WGS84转GCJ02(火星坐标系)
+ * @param lng WGS84坐标系的经度
+ * @param lat WGS84坐标系的纬度
+ * @return 火星坐标数组
+ */
+ public static double[] wgs84ToGcj02Raw(double lng, double lat) {
+ return transform(lng, lat);
+ }
+
+ /**
+ * GCJ02(火星坐标系)转WGS84
+ * @param lng 火星坐标系的经度
+ * @param lat 火星坐标系纬度
+ * @return WGS84坐标数组
+ */
+ public static double[] gcj02ToWgs84Raw(double lng, double lat) {
+ double[] out = transform(lng, lat);
+ return new double[]{lng * 2 - out[0], lat * 2 - out[1]};
+ }
+
+ /**
+ * 火星坐标系(GCJ-02)转百度坐标系(BD-09)
+ * @param lng 火星坐标经度
+ * @param lat 火星坐标纬度
+ * @return 百度坐标数组
+ * @info 谷歌、高德——>百度
+ */
+ public static double[] gcj02ToBd09(double lng, double lat) {
+ double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * X_PI);
+ double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * X_PI);
+ double bd_lng = z * Math.cos(theta) + 0.0065;
+ double bd_lat = z * Math.sin(theta) + 0.006;
+ return new double[]{bd_lng, bd_lat};
+ }
+
+ /**
+ * 百度坐标系(BD-09)转火星坐标系(GCJ-02)
+ * @param bd_lng 百度坐标纬度
+ * @param bd_lat 百度坐标经度
+ * @return 火星坐标数组
+ * @info 百度——>谷歌、高德
+ */
+ public static double[] bd09ToGcj02(double bd_lng, double bd_lat) {
+ double x = bd_lng - 0.0065;
+ double y = bd_lat - 0.006;
+ double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
+ double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
+ double gg_lng = z * Math.cos(theta);
+ double gg_lat = z * Math.sin(theta);
+ return new double[]{gg_lng, gg_lat};
+ }
+
+ /**
+ * WGS坐标转百度坐标系(BD-09)
+ * @param lng WGS84坐标系的经度
+ * @param lat WGS84坐标系的纬度
+ * @return 百度坐标数组
+ */
+ public static double[] wgs84ToBd09Raw(double lng, double lat) {
+ double[] gcj = wgs84ToGcj02Raw(lng, lat);
+ double[] bd09 = gcj02ToBd09(gcj[0], gcj[1]);
+ return bd09;
+ }
+
+ /**
+ * 百度坐标系(BD-09)转WGS坐标
+ * @param lng 百度坐标纬度
+ * @param lat 百度坐标经度
+ * @return WGS84坐标数组
+ */
+ public static double[] bd09ToWgs84Raw(double lng, double lat) {
+ double[] gcj = bd09ToGcj02(lng, lat);
+ double[] wgs84 = gcj02ToWgs84Raw(gcj[0], gcj[1]);
+ return wgs84;
+ }
+
+ private static double[] transform(final double lng, final double lat) {
+ double dlat = transformLat(lng - 105.0, lat - 35.0);
+ double dlng = transformLng(lng - 105.0, lat - 35.0);
+ double radlat = lat / 180.0 * PI;
+ double magic = Math.sin(radlat);
+ magic = 1 - EE * magic * magic;
+ double sqrtmagic = Math.sqrt(magic);
+ dlat = (dlat * 180.0) / ((A * (1 - EE)) / (magic * sqrtmagic) * PI);
+ dlng = (dlng * 180.0) / (A / sqrtmagic * Math.cos(radlat) * PI);
+ return new double[]{lng + dlng, lat + dlat};
+ }
+
+ /**
+ * 纬度转换
+ */
+ private static double transformLat(double lng, double lat) {
+ double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math
+ .sqrt(Math.abs(lng));
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
+ ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
+ ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
+ return ret;
+ }
+
+ /**
+ * 经度转换
+ */
+ private static double transformLng(double lng, double lat) {
+ double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math
+ .sqrt(Math.abs(lng));
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
+ ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
+ ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
+ return ret;
+ }
+
+ public static class Rectangle {
+
+ public final double west;
+
+ public final double north;
+
+ public final double east;
+
+ public final double south;
+
+ public Rectangle(double lng1, double lat1, double lng2, double lat2) {
+ this.west = Math.min(lng1, lng2);
+ this.north = Math.max(lat1, lat2);
+ this.east = Math.max(lng1, lng2);
+ this.south = Math.min(lat1, lat2);
+ }
+
+ public boolean contain(double lng, double lat) {
+ return this.west <= lng && this.east >= lng && this.north >= lat && this.south <= lat;
+ }
+ }
+}
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..d8f14a1
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':library'
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..01abcb6
--- /dev/null
+++ b/src/main/AndroidManifest.xml
@@ -0,0 +1,11 @@
+