├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── se
│ │ └── arbitur
│ │ └── geocodingexample
│ │ └── MainActivity.java
├── build.gradle
└── proguard-rules.pro
├── geocoding
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── se
│ │ └── arbitur
│ │ └── geocoding
│ │ ├── Constants
│ │ ├── ResponseStatuses.java
│ │ ├── AddressComponents.java
│ │ ├── LocationTypes.java
│ │ └── AddressTypes.java
│ │ ├── Models
│ │ ├── Coordinate.java
│ │ └── Bounds.java
│ │ ├── Callback.java
│ │ ├── Response.java
│ │ ├── Geocoding.java
│ │ ├── ReverseGeocoding.java
│ │ ├── Geocoder.java
│ │ └── Result.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/geocoding/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':geocoding'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/geocoding/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Geocoding
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbitur/Geocoding-Android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 30 12:59:22 CEST 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/geocoding/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Constants/ResponseStatuses.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding.Constants;
2 |
3 |
4 | public interface ResponseStatuses {
5 | String OK = "OK";
6 | String ZERO_RESULTS = "ZERO_RESULTS";
7 | String OVER_QUERY_LIMIT = "OVER_QUERY_LIMIT";
8 | String REQUEST_DENIED = "REQUEST_DENIED";
9 | String INVALID_REQUEST = "INVALID_REQUEST";
10 | String UNKNOWN_ERROR = "UNKNOWN_ERROR";
11 | }
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Models/Coordinate.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding.Models;
2 |
3 |
4 |
5 | public final class Coordinate {
6 | Double latitude;
7 | Double longitude;
8 |
9 |
10 |
11 | public Coordinate(Double latitude, Double longitude) {
12 | this.latitude = latitude;
13 | this.longitude = longitude;
14 | }
15 |
16 | public Double getLatitude() { return latitude; }
17 | public Double getLongitude() { return longitude; }
18 |
19 | @Override
20 | public String toString() { return latitude + "," + longitude; }
21 | }
22 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Constants/AddressComponents.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding.Constants;
2 |
3 |
4 | public interface AddressComponents {
5 | String ROUTE = "route"; // matches long or short name of a route.
6 | String LOCALITY = "locality"; // matches against both locality and sublocality types.
7 | String ADMINISTRATIVE_AREA = "administrative_area"; // matches all the administrative_area levels.
8 | String POSTAL_CODE = "postal_code"; // matches postal_code and postal_code_prefix.
9 | String COUNTRY = "country"; // matches a country name or a two letter ISO 3166-1 country code.
10 | }
11 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Models/Bounds.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding.Models;
2 |
3 |
4 | public final class Bounds {
5 | private Coordinate southWest;
6 | private Coordinate northEast;
7 |
8 | public Bounds(Coordinate southWest, Coordinate northEast) {
9 | this.southWest = southWest;
10 | this.northEast = northEast;
11 | }
12 |
13 | public Bounds(double swLat, double swLong, double neLat, double neLong) {
14 | southWest = new Coordinate(swLat, swLong);
15 | northEast = new Coordinate(neLat, neLong);
16 | }
17 |
18 | @Override
19 | public String toString() {
20 | return southWest.toString() + "|" + northEast.toString();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/geocoding/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "27.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 27
10 | versionCode 3
11 | versionName "1.1.3"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 |
24 | implementation 'com.squareup.okhttp3:okhttp:3.+'
25 | implementation 'com.squareup.okhttp3:logging-interceptor:3.+'
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "27.0.3"
6 | defaultConfig {
7 | applicationId "se.arbitur.geocodingexample"
8 | minSdkVersion 21
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0.1"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:27.+'
24 |
25 | implementation project(':geocoding')
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Constants/LocationTypes.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding.Constants;
2 |
3 |
4 | public interface LocationTypes {
5 | String ROOFTOP = "ROOFTOP"; // addresses for which we have location information accurate down to street address precision.
6 | String RANGE_INTERPOLATED = "RANGE_INTERPOLATED"; // those that reflect an approximation (usually on a road) interpolated between two precise points (such as intersections). An interpolated range generally indicates that rooftop geocodes are unavailable for a street address.
7 | String GEOMETRIC_CENTER = "GEOMETRIC_CENTER"; // geometric centers of a location such as a polyline (for example, a street) or polygon (region).
8 | String APPROXIMATE = "APPROXIMATE"; // those that are characterized as approximate.
9 | }
10 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Callback.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding;
2 |
3 |
4 | import java.io.IOException;
5 |
6 |
7 |
8 | public interface Callback {
9 | /**
10 | * response is not null and {@link Response#status status} is equal to {@link se.arbitur.geocoding.Constants.ResponseStatuses#OK OK}
11 | * @param response The response
12 | */
13 | void onResponse(Response response);
14 |
15 | /**
16 | * If {@link Response#status status} is anything but {@link se.arbitur.geocoding.Constants.ResponseStatuses#OK OK} then response wont be null.
17 | * If an exception was thrown by OkHttp then exception wont be null.
18 | * @param response @Nullable The response
19 | * @param exception @Nullable The exception
20 | */
21 | void onFailed(Response response, IOException exception);
22 | }
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 | strings.xml
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # Intellij
37 | *.iml
38 | .idea/workspace.xml
39 | .idea/tasks.xml
40 | .idea/gradle.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Arbitur/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/geocoding/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/Arbitur/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Response.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding;
2 |
3 |
4 | import org.json.JSONArray;
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 |
12 |
13 | public final class Response {
14 | Result[] results;
15 | String status;
16 | String errorMessage;
17 |
18 |
19 | public Result[] getResults() { return results; }
20 | public String getStatus() { return status; }
21 | public String getErrorMessage() { return errorMessage; }
22 |
23 | public Result[] getResults(String addressType) {
24 | List filter = new ArrayList<>();
25 |
26 | for (Result result : getResults())
27 | for (int i = 0; i < result.getAddressTypes().length; i++) {
28 | String type = result.getAddressTypes()[i];
29 | if (type.equals(addressType)) {
30 | filter.add(result);
31 | break;
32 | }
33 | }
34 |
35 | return filter.toArray(new Result[filter.size()]);
36 | }
37 |
38 |
39 | protected Response(JSONObject json) throws JSONException {
40 | if (json.has("results")) {
41 | JSONArray jsonResults = json.getJSONArray("results");
42 | results = new Result[jsonResults.length()];
43 | for (int i = 0; i < jsonResults.length(); i++)
44 | results[i] = new Result(jsonResults.getJSONObject(i));
45 | }
46 |
47 | status = json.getString("status");
48 |
49 | if (json.has("error_message"))
50 | errorMessage = json.getString("error_message");
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Geocoding.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding;
2 |
3 |
4 | import android.text.TextUtils;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import okhttp3.HttpUrl;
10 | import se.arbitur.geocoding.Models.Bounds;
11 |
12 |
13 |
14 | public final class Geocoding extends Geocoder {
15 | String query;
16 | Bounds bounds;
17 | String region;
18 | List components = new ArrayList<>();
19 |
20 |
21 |
22 | public Geocoding(String query, String key) {
23 | super(key);
24 | this.query = query;
25 | }
26 |
27 |
28 | @Override
29 | protected HttpUrl.Builder getUrlBuilder() {
30 | HttpUrl.Builder builder = getDefaultUrlBuilder();
31 |
32 | builder.addQueryParameter("address", query);
33 |
34 | if (bounds != null) builder.addQueryParameter("bounds", bounds.toString());
35 | if (region != null) builder.addQueryParameter("region", region);
36 | if (!components.isEmpty()) builder.addQueryParameter("components", TextUtils.join("|", components));
37 |
38 | return builder;
39 | }
40 |
41 |
42 |
43 | /**
44 | * Set language for values.
45 | * @see List of supported languages
46 | * @param language Language code ex: "en", "sv"
47 | */
48 | public Geocoding setLanguage(String language) {
49 | this.language = language;
50 | return this;
51 | }
52 |
53 | /**
54 | * Set prioritized bounds, searches within bounds first
55 | * @param bounds The bounds, southWest -> northEast
56 | * @return
57 | */
58 | public Geocoding setBounds(Bounds bounds) {
59 | this.bounds = bounds;
60 | return this;
61 | }
62 |
63 | /**
64 | * Set the region
65 | * @param region a ccTLD (Country Code Top Level Domain) ex: uk, es, us
66 | */
67 | public Geocoding setRegion(String region) {
68 | this.region = region;
69 | return this;
70 | }
71 |
72 | /**
73 | * Add a component.
74 | * Available types are {@link se.arbitur.geocoding.Constants.AddressTypes AddressTypes}.[ROUTE, LOCALITY, ADMINISTRATIVE_AREA, POSTAL_CODE, COUNTRY]
75 | * @param addressType The type
76 | * @param value The value
77 | */
78 | public Geocoding addComponent(String addressType, String value) {
79 | components.add(addressType.toLowerCase() + ":" + value);
80 | return this;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/ReverseGeocoding.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding;
2 |
3 |
4 | import android.text.TextUtils;
5 |
6 | import okhttp3.HttpUrl;
7 | import se.arbitur.geocoding.Models.Coordinate;
8 |
9 |
10 |
11 | public final class ReverseGeocoding extends Geocoder {
12 | String placeId;
13 | Coordinate coordinate;
14 |
15 | String[] resultTypes;
16 | String[] locationTypes;
17 | Boolean isSensor;
18 |
19 |
20 |
21 | public ReverseGeocoding(Coordinate coordinate, String key) {
22 | super(key);
23 | this.coordinate = coordinate;
24 | }
25 |
26 | public ReverseGeocoding(double latitude, double longitude, String key) {
27 | this(new Coordinate(latitude, longitude), key);
28 | }
29 |
30 | public ReverseGeocoding(String placeId, String key) {
31 | super(key);
32 | this.placeId = placeId;
33 | }
34 |
35 |
36 |
37 | @Override
38 | protected HttpUrl.Builder getUrlBuilder() {
39 | HttpUrl.Builder builder = getDefaultUrlBuilder();
40 |
41 | if (coordinate != null) {
42 | builder.addQueryParameter("latlng", coordinate.toString());
43 | if (resultTypes != null) builder.addQueryParameter("result_type", TextUtils.join("|", resultTypes).toLowerCase());
44 | if (locationTypes != null) builder.addQueryParameter("location_type=", TextUtils.join("|", locationTypes).toLowerCase());
45 | if (isSensor != null) builder.addQueryParameter("sensor", isSensor.toString());
46 | }
47 | else
48 | builder.addQueryParameter("place_id", placeId);
49 |
50 | return builder;
51 | }
52 |
53 |
54 |
55 | /**
56 | * Set language for values.
57 | * @see List of supported languages
58 | * @param language Language code ex: "en", "sv"
59 | */
60 | public ReverseGeocoding setLanguage(String language) {
61 | this.language = language;
62 | return this;
63 | }
64 |
65 | /**
66 | * Set result types.
67 | * Available types found in {@link se.arbitur.geocoding.Constants.AddressComponents AddressComponents}
68 | * @param types The types
69 | */
70 | public ReverseGeocoding setResultTypes(String... types) {
71 | this.resultTypes = types;
72 | return this;
73 | }
74 |
75 | /**
76 | * Set location types.
77 | * Available types found in {@link se.arbitur.geocoding.Constants.LocationTypes LocationTypes}
78 | * @param types The types
79 | */
80 | public ReverseGeocoding setLocationTypes(String... types) {
81 | this.locationTypes = types;
82 | return this;
83 | }
84 |
85 | /**
86 | * Set isSensor
87 | * @param isSensor If sensor
88 | */
89 | public ReverseGeocoding isSensor(boolean isSensor) {
90 | this.isSensor = isSensor;
91 | return this;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Geocoding-Android
2 |
3 | This is a Java wrapper for Google's [Geocoding Web API](https://developers.google.com/maps/documentation/geocoding)
4 |
5 | ## Install
6 |
7 | > Root build.gradle
8 | ```gradle
9 | allprojects {
10 | repositories {
11 | maven { url 'https://jitpack.io' }
12 | }
13 | }
14 | ```
15 |
16 | > Module build.gradle
17 | ```gradle
18 | dependencies {
19 | implementation 'com.github.arbitur:Geocoding-Android:'
20 | }
21 | ```
22 |
23 | ## Usage
24 |
25 | #### Geocoding (Query search)
26 |
27 | ```java
28 | new Geocoding(query, apiKey /* or null */)
29 | .setLanguage(language)
30 | .setBounds(new Bounds(sw, ne))
31 | .setRegion(region)
32 | .addComponent(type, value)
33 | ...
34 | .fetch(...);
35 | ```
36 |
37 | #### Reverse Geocoding (Coordinate search)
38 |
39 | ```java
40 | new ReverseGeocoding(coordinate, apiKey /* or null */)
41 | .setLanguage(language)
42 | .setResultTypes(resultType1, resultType2 ...)
43 | .setLocationTypes(locationType1, locationType2 ...)
44 | .isSensor(isSensor)
45 | .fetch(...);
46 | ```
47 |
48 | #### Reverse Geocoding (Place ID search)
49 |
50 | ```java
51 | new ReverseGeocoding(placeId, apiKey /* or null */)
52 | .setLanguage(language)
53 | .fetch(...);
54 | ```
55 |
56 | ## Examples
57 |
58 | ```java
59 | new Geocoding("Stockholm", key) // City
60 | .setLanguage("sv")
61 | .setRegion("se")
62 | .addComponent(AddressTypes.COUNTRY, "Sweden")
63 | .fetch(...);
64 |
65 |
66 | new Geocoding("Humlegården", key) // Park
67 | .setLanguage("sv")
68 | .addComponent(AddressTypes.ADMINISTRATIVE_AREA_LEVEL_1, "Stockholm")
69 | .fetch(...);
70 |
71 |
72 | new Geocoding("Östermalmstorg 1, Stockholm, Sweden", key) // Street Address
73 | .setLanguage("sv")
74 | .setBounds(new Bounds(59.3, 18.01, 59.354, 18.116))
75 | .fetch(...);
76 |
77 |
78 | new ReverseGeocoding(59.336, 18.079, apiKey)
79 | .setLanguage("sv")
80 | .setResultTypes(AdressTypes.STREET_ADDRESS)
81 | .setLocationTypes(LocationTypes.ROOF_TOP)
82 | .isSensor(true)
83 | .fetch(...);
84 | ```
85 |
86 | #### Fetching
87 |
88 | ```java
89 | ...
90 | .fetch(new Callback() {
91 | @Override
92 | public void onResponse(Response response) {
93 | for (Result result : response.getResults()) {
94 | Log.d(TAG, result.getFormattedAddress());
95 |
96 | addMarkerTo(result.getGeometry().getLocation())
97 | }
98 |
99 | Result[] addresses = response.getResults(AddressTypes.STREET_ADDRESS);
100 | Result[] routes = response.getResults(AddressTypes.ROUTE);
101 |
102 | ...
103 | }
104 |
105 | @Override
106 | public void onFailed(Response response, IOException exception) {
107 | Log.d(TAG, "Something went wrong");
108 | }
109 | })
110 | ```
111 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Geocoder.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import java.io.IOException;
10 |
11 | import okhttp3.Call;
12 | import okhttp3.HttpUrl;
13 | import okhttp3.OkHttpClient;
14 | import okhttp3.Request;
15 | import okhttp3.logging.HttpLoggingInterceptor;
16 | import se.arbitur.geocoding.Constants.ResponseStatuses;
17 |
18 |
19 |
20 | public abstract class Geocoder {
21 | public static HttpLoggingInterceptor.Level loggingLevel = HttpLoggingInterceptor.Level.BODY;
22 |
23 | protected static HttpUrl.Builder getDefaultUrlBuilder() {
24 | return new HttpUrl.Builder()
25 | .scheme("https")
26 | .host("maps.googleapis.com")
27 | .addPathSegment("maps")
28 | .addPathSegment("api")
29 | .addPathSegment("geocode")
30 | .addPathSegment("json");
31 | }
32 |
33 | protected String key;
34 | protected String language;
35 |
36 |
37 |
38 | protected Geocoder(String key) {
39 | this.key = key;
40 | }
41 |
42 |
43 |
44 | protected abstract HttpUrl.Builder getUrlBuilder();
45 |
46 |
47 |
48 | public void fetch(final Callback callback) {
49 | OkHttpClient httpClient = new OkHttpClient.Builder()
50 | .addInterceptor(new HttpLoggingInterceptor().setLevel(loggingLevel))
51 | .build();
52 |
53 |
54 | HttpUrl.Builder url = getUrlBuilder();
55 |
56 | if (language != null) url.addQueryParameter("language", language);
57 | if (key != null) url.addQueryParameter("key", key);
58 |
59 | Request request = new Request.Builder()
60 | .url(url.build())
61 | .build();
62 |
63 | httpClient.newCall(request).enqueue(new okhttp3.Callback() {
64 | Handler handler = new Handler(Looper.getMainLooper());
65 |
66 | @Override
67 | public void onFailure(Call call, final IOException e) {
68 | handler.post(new Runnable() {
69 | @Override
70 | public void run() {
71 | callback.onFailed(null, e);
72 | }
73 | });
74 | }
75 |
76 | @Override
77 | public void onResponse(Call call, okhttp3.Response response) throws IOException {
78 | String json = response.body().string();
79 |
80 | try {
81 | final Response geoResponse = new Response(new JSONObject(json));
82 |
83 | if (geoResponse.getStatus().equals(ResponseStatuses.OK)) {
84 | handler.post(new Runnable() {
85 | @Override
86 | public void run() {
87 | callback.onResponse(geoResponse);
88 | }
89 | });
90 | }
91 | else {
92 | handler.post(new Runnable() {
93 | @Override
94 | public void run() {
95 | callback.onFailed(geoResponse, null);
96 | }
97 | });
98 | }
99 | }
100 | catch (JSONException e) {
101 | throw new IOException(e.getMessage());
102 | }
103 | }
104 | });
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/se/arbitur/geocodingexample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocodingexample;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 |
7 | import java.io.IOException;
8 |
9 | import okhttp3.logging.HttpLoggingInterceptor;
10 | import se.arbitur.geocoding.Geocoding;
11 | import se.arbitur.geocoding.Callback;
12 | import se.arbitur.geocoding.Geocoder;
13 | import se.arbitur.geocoding.Constants.AddressTypes;
14 | import se.arbitur.geocoding.Constants.LocationTypes;
15 | import se.arbitur.geocoding.Models.Coordinate;
16 | import se.arbitur.geocoding.ReverseGeocoding;
17 | import se.arbitur.geocoding.Response;
18 | import se.arbitur.geocoding.Result;
19 |
20 |
21 |
22 | public class MainActivity extends AppCompatActivity {
23 | private static final String TAG = "MainActivity";
24 |
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | Geocoder.loggingLevel = HttpLoggingInterceptor.Level.BASIC;
32 |
33 | addressSearch("Humlegården");
34 | coordinateSearch(new Coordinate(59.3, 20.0));
35 | placeIdSearch("EiZGcsO2c8OkdHJhYmFja2VuLCBTa8OkcmhvbG1lbiwgU3ZlcmlnZQ");
36 | }
37 |
38 |
39 |
40 |
41 |
42 | private void addressSearch(String query) {
43 | new Geocoding(query, getString(R.string.geocoding_key))
44 | .setLanguage("sv")
45 | .addComponent(AddressTypes.ADMINISTRATIVE_AREA_LEVEL_1, "Stockholm")
46 | .fetch(geoCallback);
47 | }
48 |
49 |
50 |
51 | private void coordinateSearch(Coordinate coordinate) {
52 | new ReverseGeocoding(coordinate, getString(R.string.geocoding_key))
53 | .setLocationTypes(LocationTypes.ROOFTOP)
54 | .setResultTypes(AddressTypes.STREET_ADDRESS)
55 | .isSensor(true)
56 | .fetch(geoCallback);
57 | }
58 |
59 |
60 | private void placeIdSearch(String placeId) {
61 | new ReverseGeocoding(placeId, getString(R.string.geocoding_key))
62 | .setLanguage("sv")
63 | .fetch(geoCallback);
64 | }
65 |
66 |
67 |
68 | Callback geoCallback = new Callback() {
69 | @Override
70 | public void onResponse(Response response) {
71 | Log.d(TAG, "Status code: " + response.getStatus());
72 | Log.d(TAG, "Responses: " + response.getResults().length);
73 |
74 | for (Result result : response.getResults()) {
75 | Log.d(TAG, " Formatted address: " + result.getFormattedAddress());
76 | Log.d(TAG, " Place ID: " + result.getPlaceId());
77 | Log.d(TAG, " Location: " + result.getGeometry().getLocation());
78 | Log.d(TAG, " Location type: " + result.getGeometry().getLocationType());
79 | Log.d(TAG, " SouthWest: " + result.getGeometry().getViewport().getSouthWest());
80 | Log.d(TAG, " NorthEast: " + result.getGeometry().getViewport().getNorthEast());
81 | Log.d(TAG, " Types:");
82 | for (int i = 0; i < result.getAddressTypes().length; i++)
83 | Log.d(TAG, " " + result.getAddressTypes()[i]);
84 | }
85 | }
86 |
87 | @Override
88 | public void onFailed(Response response, IOException exception) {
89 | if (response != null) Log.e(TAG, (response.getErrorMessage() == null) ? response.getStatus() : response.getErrorMessage());
90 | else Log.e(TAG, exception.getLocalizedMessage());
91 | }
92 | };
93 | }
94 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Constants/AddressTypes.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding.Constants;
2 |
3 |
4 | public interface AddressTypes {
5 | String STREET_ADDRESS = "street_address"; // a precise street address.
6 | String ROUTE = "route"; // a named route (such as "US 101").
7 | String INTERSECTION = "intersection"; // a major intersection, usually of two major roads.
8 | String POLITICAL = "political"; // a political entity. Usually, this type indicates a polygon of some civil administration.
9 | String COUNTRY = "country"; // the national political entity, and is typically the highest order type returned by the Geocoder.
10 | String ADMINISTRATIVE_AREA_LEVEL_1 = "administrative_area_level_1"; // a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels.
11 | String ADMINISTRATIVE_AREA_LEVEL_2 = "administrative_area_level_2"; // a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.
12 | String ADMINISTRATIVE_AREA_LEVEL_3 = "administrative_area_level_3"; // a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
13 | String ADMINISTRATIVE_AREA_LEVEL_4 = "administrative_area_level_4"; // a fourth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
14 | String ADMINISTRATIVE_AREA_LEVEL_5 = "administrative_area_level_5"; // a fifth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
15 | String COLLOQUIAL_AREA = "colloquial_area"; // a commonly-used alternative name for the entity.
16 | String LOCALITY = "locality"; // an incorporated city or town political entity.
17 | String WARD = "ward"; // a specific type of Japanese locality, to facilitate distinction between multiple locality components within a Japanese address.
18 | String SUBLOCALITY = "sublocality"; // a first-order civil entity below a locality. For some locations may receive one of the additional types: sublocality_level_1 to sublocality_level_5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area.
19 | String SUBLOCALITY_LEVEL_1 = "sublocality_level_1";
20 | String SUBLOCALITY_LEVEL_2 = "sublocality_level_2";
21 | String SUBLOCALITY_LEVEL_3 = "sublocality_level_3";
22 | String SUBLOCALITY_LEVEL_4 = "sublocality_level_4";
23 | String SUBLOCALITY_LEVEL_5 = "sublocality_level_5";
24 | String NEIGHBORHOOD = "neighborhood"; // a named neighborhood
25 | String PREMISE = "premise"; // a named location, usually a building or collection of buildings with a common name
26 | String SUBPREMISE = "subpremise"; // a first-order entity below a named location, usually a singular building within a collection of buildings with a common name
27 | String POSTAL_CODE = "postal_code"; // a postal code as used to address postal mail within the country.
28 | String NATURAL_FEATURE = "natural_feature"; // a prominent natural feature.
29 | String AIRPORT = "airport"; // an airport.
30 | String PARK = "park"; // a named park.
31 | String POINT_OF_INTEREST = "point_of_interest"; // a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category, such as "Empire State Building" or "Statue of Liberty."
32 | String STREET_NUMBER = "street_number"; // the precise street number.
33 | String POSTAL_TOWN = "postal_town"; // indicates a grouping of geographic areas, such as locality and sublocality, used for mailing addresses in some countries
34 | }
35 |
--------------------------------------------------------------------------------
/geocoding/src/main/java/se/arbitur/geocoding/Result.java:
--------------------------------------------------------------------------------
1 | package se.arbitur.geocoding;
2 |
3 |
4 | import org.json.JSONArray;
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import se.arbitur.geocoding.Models.Coordinate;
12 |
13 |
14 |
15 | public final class Result {
16 | AddressComponent[] addressComponents;
17 | String formattedAddress;
18 | Geometry geometry;
19 | String[] addressTypes;
20 | String placeId;
21 |
22 |
23 |
24 | protected Result(JSONObject json) throws JSONException {
25 | JSONArray jsonAddressComponents = json.getJSONArray("address_components");
26 | addressComponents = new AddressComponent[jsonAddressComponents.length()];
27 | for (int i = 0; i < jsonAddressComponents.length(); i++)
28 | addressComponents[i] = new AddressComponent(jsonAddressComponents.getJSONObject(i));
29 |
30 | formattedAddress = json.getString("formatted_address");
31 | geometry = new Geometry(json.getJSONObject("geometry"));
32 |
33 | JSONArray jsonAddressTypes = json.getJSONArray("types");
34 | addressTypes = new String[jsonAddressTypes.length()];
35 | for (int i = 0; i < jsonAddressTypes.length(); i++)
36 | addressTypes[i] = jsonAddressTypes.getString(i);
37 |
38 | placeId = json.getString("place_id");
39 | }
40 |
41 |
42 | public Geometry getGeometry() {
43 | return geometry;
44 | }
45 |
46 | public AddressComponent[] getAddressComponents() {
47 | return addressComponents;
48 | }
49 |
50 | public String[] getAddressTypes() {
51 | return addressTypes;
52 | }
53 |
54 | public String getFormattedAddress() {
55 | return formattedAddress;
56 | }
57 |
58 | public String getPlaceId() {
59 | return placeId;
60 | }
61 |
62 | public AddressComponent[] getAddressComponents(String addressType) {
63 | List filter = new ArrayList<>();
64 |
65 | for (AddressComponent component : getAddressComponents())
66 | for (int i = 0; i < component.getAddressTypes().length; i++) {
67 | String type = component.getAddressTypes()[i];
68 | if (type.equals(addressType)) {
69 | filter.add(component);
70 | break;
71 | }
72 | }
73 |
74 | return filter.toArray(new AddressComponent[filter.size()]);
75 | }
76 |
77 |
78 |
79 |
80 |
81 | public static final class AddressComponent {
82 | String longName;
83 | String shortName;
84 | String[] addressTypes;
85 |
86 |
87 | protected AddressComponent(JSONObject json) throws JSONException {
88 | longName = json.getString("long_name");
89 | shortName = json.getString("short_name");
90 |
91 | JSONArray jsonTypes = json.getJSONArray("types");
92 | addressTypes = new String[jsonTypes.length()];
93 | for (int i = 0; i < jsonTypes.length(); i++)
94 | addressTypes[i] = jsonTypes.getString(i);
95 | }
96 |
97 |
98 | public String[] getAddressTypes() {
99 | return addressTypes;
100 | }
101 |
102 | public String getLongName() {
103 | return longName;
104 | }
105 |
106 | public String getShortName() {
107 | return shortName;
108 | }
109 | }
110 |
111 |
112 |
113 |
114 |
115 | public static final class Geometry {
116 | Coordinate location;
117 | String locationType;
118 | Viewport viewport;
119 |
120 |
121 | protected Geometry(JSONObject json) throws JSONException {
122 | JSONObject jsonLocation = json.getJSONObject("location");
123 | location = new Coordinate(jsonLocation.getDouble("lat"), jsonLocation.getDouble("lng"));
124 |
125 | locationType = json.getString("location_type");
126 | viewport = new Viewport(json.getJSONObject("viewport"));
127 | }
128 |
129 |
130 | public Coordinate getLocation() {
131 | return location;
132 | }
133 |
134 | public String getLocationType() {
135 | return locationType;
136 | }
137 |
138 | public Viewport getViewport() {
139 | return viewport;
140 | }
141 |
142 |
143 |
144 |
145 | public static final class Viewport {
146 | Coordinate southWest;
147 | Coordinate northEast;
148 |
149 |
150 | protected Viewport(JSONObject json) throws JSONException {
151 | JSONObject jsonSW = json.getJSONObject("southwest");
152 | southWest = new Coordinate(jsonSW.getDouble("lat"), jsonSW.getDouble("lng"));
153 |
154 | JSONObject jsonNE = json.getJSONObject("northeast");
155 | northEast = new Coordinate(jsonNE.getDouble("lat"), jsonNE.getDouble("lng"));
156 | }
157 |
158 |
159 | public Coordinate getNorthEast() {
160 | return northEast;
161 | }
162 |
163 | public Coordinate getSouthWest() {
164 | return southWest;
165 | }
166 | }
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------