├── demo ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── tanapruk │ │ │ └── reversegeocodedemo │ │ │ └── MainActivity.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── tanapruk │ │ └── reversegeocodedemo │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── reversegeocode ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── tanapruk │ │ │ └── reversegeocode │ │ │ ├── Polygon │ │ │ ├── Point.java │ │ │ ├── Line.java │ │ │ └── Polygon.java │ │ │ ├── GeocodeListBuilder.java │ │ │ └── GeocodeList.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── tanapruk │ │ │ └── reversegeocode │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── tanapruk │ │ └── reversegeocode │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /reversegeocode/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':demo' 2 | include ':reversegeocode' 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.gradle 2 | **/local.properties 3 | **/.idea 4 | .DS_Store 5 | **/build 6 | **/captures 7 | **/*.iml 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tanapruk/ReverseGeocodeCountry/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /reversegeocode/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ReverseGeocode 3 | 4 | -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tanapruk/ReverseGeocodeCountry/HEAD/demo/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tanapruk/ReverseGeocodeCountry/HEAD/demo/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tanapruk/ReverseGeocodeCountry/HEAD/demo/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tanapruk/ReverseGeocodeCountry/HEAD/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 48dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jun 29 13:57:15 ICT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip 7 | -------------------------------------------------------------------------------- /reversegeocode/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /demo/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /demo/src/androidTest/java/com/tanapruk/reversegeocodedemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.tanapruk.reversegeocodedemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /reversegeocode/src/main/java/com/tanapruk/reversegeocode/Polygon/Point.java: -------------------------------------------------------------------------------- 1 | package com.tanapruk.reversegeocode.Polygon; 2 | /** 3 | * Point on 2D landscape 4 | * 5 | * @author Roman Kushnarenko (sromku@gmail.com)
6 | */ 7 | public class Point 8 | { 9 | public Point(float x, float y) 10 | { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | 15 | public float x; 16 | public float y; 17 | 18 | @Override 19 | public String toString() 20 | { 21 | return String.format("(%.2f,%.2f)", x, y); 22 | } 23 | } -------------------------------------------------------------------------------- /reversegeocode/src/test/java/com/tanapruk/reversegeocode/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.tanapruk.reversegeocode; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /demo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Reverse Geocode Country 3 | 4 | 5 | Settings 6 | Input Your Latitude and Longitude 7 | Latitude: 8 | Longitude: 9 | 000.000000 10 | Find 11 | Result 12 | Country ID: 13 | Country Name: 14 | 15 | 16 | -------------------------------------------------------------------------------- /demo/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/trusttanapruk/Documents/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 | -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion '23.0.3' 6 | 7 | defaultConfig { 8 | applicationId "com.tanapruk.reversegeocodecountry" 9 | minSdkVersion 15 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile 'com.android.support:appcompat-v7:24.0.0' 25 | compile project(path: ':reversegeocode') 26 | } 27 | -------------------------------------------------------------------------------- /reversegeocode/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/trusttanapruk/Documents/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 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /reversegeocode/src/androidTest/java/com/tanapruk/reversegeocode/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tanapruk.reversegeocode; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.tanap.reversegeocode.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /demo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 14 | 15 | 20 | 21 | 25 | 26 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /reversegeocode/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:24.0.0' 30 | compile 'com.google.code.gson:gson:2.4' 31 | testCompile 'junit:junit:4.12' 32 | } 33 | -------------------------------------------------------------------------------- /reversegeocode/src/main/java/com/tanapruk/reversegeocode/GeocodeListBuilder.java: -------------------------------------------------------------------------------- 1 | package com.tanapruk.reversegeocode; 2 | 3 | import android.content.Context; 4 | 5 | import com.google.gson.Gson; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | /** 11 | * Created by Tanapruk on 8/11/15 AD. 12 | */ 13 | public class GeocodeListBuilder { 14 | 15 | final static private String filepath = "ReverseGeocodeCountryWithName.json"; 16 | 17 | public static String getCountryName(Context context , Double latitude, Double longitude) { 18 | return getGeocodeListFromJSON(context).getCountryName(latitude,longitude); 19 | } 20 | 21 | public static String getCountryId(Context context, Double latitude, Double longitude) { 22 | return getGeocodeList(context).getCountryId(latitude,longitude); 23 | } 24 | 25 | private static GeocodeList getGeocodeList(Context context) { 26 | return getGeocodeListFromJSON(context); 27 | } 28 | 29 | private static GeocodeList getGeocodeListFromJSON(Context context) { 30 | String jsonString = getJSONFromAsset(context); 31 | Gson gson = new Gson(); 32 | return gson.fromJson(jsonString, GeocodeList.class); 33 | } 34 | 35 | private static String getJSONFromAsset(Context context) { 36 | String json = null; 37 | try { 38 | InputStream is = context.getAssets().open(filepath); 39 | int size = is.available(); 40 | byte[] buffer = new byte[size]; 41 | is.read(buffer); 42 | is.close(); 43 | json = new String(buffer, "UTF-8"); 44 | } catch (IOException ex) { 45 | ex.printStackTrace(); 46 | return null; 47 | } 48 | return json; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /demo/src/main/java/com/tanapruk/reversegeocodedemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tanapruk.reversegeocodedemo; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.EditText; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | 12 | import com.tanapruk.reversegeocode.GeocodeListBuilder; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_main); 20 | 21 | 22 | Button btnFind = (Button) findViewById(R.id.btn_find_country); 23 | btnFind.setOnClickListener(new View.OnClickListener() { 24 | @Override 25 | public void onClick(View v) { 26 | 27 | EditText editLatitude = (EditText) findViewById(R.id.edit_latitude); 28 | EditText editLongitude = (EditText) findViewById(R.id.edit_longitude); 29 | TextView textCountryId = (TextView) findViewById(R.id.text_country_id); 30 | TextView textCountryName = (TextView) findViewById(R.id.text_country_name); 31 | Context context = getApplicationContext(); 32 | 33 | Double latitude = Double.valueOf(editLatitude.getText().toString()); 34 | Double longitude = Double.valueOf(editLongitude.getText().toString()); 35 | 36 | 37 | String countryId = GeocodeListBuilder.getCountryId(context, latitude, longitude); 38 | String countryName = GeocodeListBuilder.getCountryName(context, latitude, longitude); 39 | 40 | 41 | textCountryId.setText(countryId); 42 | textCountryName.setText(countryName); 43 | 44 | Toast.makeText(context, "ID: " + countryId + " " + " Name: " + countryName, Toast.LENGTH_SHORT).show(); 45 | 46 | } 47 | }); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Offline Reverse Geocode Country 2 | 3 | A module for getting a country name and country code when given a specific latitude and longitude. It works offline. No need for an Internet connection. 4 | 5 | 6 | ## Usage 7 | ##### Copy the following files to your project: 8 | 1. Polygon folder 9 | 1. Line 10 | 2. Point 11 | 3. Polygon 12 | 2. GeocoderList.java 13 | 3. GeocoderListBuilder.java 14 | 4. ReverseGeocodeCountryWithName.json (in assets folder) 15 | 16 | The code is simplified to one line. 17 | ``` 18 | String countryId = GeocodeListBuilder.getCountryId(context, latitude, longitude); 19 | String countryName = GeocodeListBuilder.getCountryName(context, latitude, longitude); 20 | 21 | ``` 22 | 23 | ## Sample App 24 | 25 | 26 | [Reverse Geocode Country on Play Store](https://play.google.com/store/apps/details?id=com.tanapruk.reversegeocodecountry) 27 | 28 | ## Attribution 29 | The code here are combine from: 30 | 31 | 32 | 1. [ios-offline-reverse-geocode-country](https://github.com/krisrak/ios-offline-reverse-geocode-country) 33 | I modified the JSON file so that it is easier to deserialization in android. 34 | 35 | 2. [polygon-contains-point](https://github.com/sromku/polygon-contains-point) 36 | This module helps locate a given latitude and longitude whether it is in a polygon of a given country. 37 | 38 | ## License 39 | The MIT License (MIT) 40 | 41 | Copyright (c) 2015 Tanapruk Tangphianphan 42 | ``` 43 | Permission is hereby granted, free of charge, to any person obtaining a copy 44 | of this software and associated documentation files (the "Software"), to deal 45 | in the Software without restriction, including without limitation the rights 46 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 47 | copies of the Software, and to permit persons to whom the Software is 48 | furnished to do so, subject to the following conditions: 49 | 50 | The above copyright notice and this permission notice shall be included in all 51 | copies or substantial portions of the Software. 52 | 53 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 55 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 56 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 57 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 59 | SOFTWARE. 60 | ``` -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows 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 | -------------------------------------------------------------------------------- /reversegeocode/src/main/java/com/tanapruk/reversegeocode/Polygon/Line.java: -------------------------------------------------------------------------------- 1 | package com.tanapruk.reversegeocode.Polygon; 2 | 3 | /** 4 | * Line is defined by starting point and ending point on 2D dimension.
5 | * 6 | * @author Roman Kushnarenko (sromku@gmail.com) 7 | */ 8 | public class Line 9 | { 10 | private final Point _start; 11 | private final Point _end; 12 | private float _a = Float.NaN; 13 | private float _b = Float.NaN; 14 | private boolean _vertical = false; 15 | 16 | public Line(Point start, Point end) 17 | { 18 | _start = start; 19 | _end = end; 20 | 21 | if (_end.x - _start.x != 0) 22 | { 23 | _a = ((_end.y - _start.y) / (_end.x - _start.x)); 24 | _b = _start.y - _a * _start.x; 25 | } 26 | 27 | else 28 | { 29 | _vertical = true; 30 | } 31 | } 32 | 33 | /** 34 | * Indicate whereas the point lays on the line. 35 | * 36 | * @param point 37 | * - The point to check 38 | * @return True if the point lays on the line, otherwise return False 39 | */ 40 | public boolean isInside(Point point) 41 | { 42 | float maxX = _start.x > _end.x ? _start.x : _end.x; 43 | float minX = _start.x < _end.x ? _start.x : _end.x; 44 | float maxY = _start.y > _end.y ? _start.y : _end.y; 45 | float minY = _start.y < _end.y ? _start.y : _end.y; 46 | 47 | if ((point.x >= minX && point.x <= maxX) && (point.y >= minY && point.y <= maxY)) 48 | { 49 | return true; 50 | } 51 | return false; 52 | } 53 | 54 | /** 55 | * Indicate whereas the line is vertical.
56 | * For example, line like x=1 is vertical, in other words parallel to axis Y.
57 | * In this case the A is (+/-)infinite. 58 | * 59 | * @return True if the line is vertical, otherwise return False 60 | */ 61 | public boolean isVertical() 62 | { 63 | return _vertical; 64 | } 65 | 66 | /** 67 | * y = Ax + B 68 | * 69 | * @return The A 70 | */ 71 | public float getA() 72 | { 73 | return _a; 74 | } 75 | 76 | /** 77 | * y = Ax + B 78 | * 79 | * @return The B 80 | */ 81 | public float getB() 82 | { 83 | return _b; 84 | } 85 | 86 | /** 87 | * Get start point 88 | * 89 | * @return The start point 90 | */ 91 | public Point getStart() 92 | { 93 | return _start; 94 | } 95 | 96 | /** 97 | * Get end point 98 | * 99 | * @return The end point 100 | */ 101 | public Point getEnd() 102 | { 103 | return _end; 104 | } 105 | 106 | @Override 107 | public String toString() 108 | { 109 | return String.format("%s-%s", _start.toString(), _end.toString()); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 21 | 25 | 26 | 33 | 43 | 44 | 45 | 49 | 50 | 57 | 67 | 68 | 69 | 70 | 71 |