项目作者: akexorcist

项目描述 :
[Android] Library for Google Direction API for Google Maps Android API v2
高级语言: Java
项目地址: git://github.com/akexorcist/GoogleDirectionLibrary.git
创建时间: 2015-11-30T00:48:42Z
项目社区:https://github.com/akexorcist/GoogleDirectionLibrary

开源协议:Apache License 2.0

下载


Android Arsenal
Maven Central
Minimum SDK Version
Workflow Status

Android-GoogleDirectionLibrary

Google Direction Library

Google Maps Direction API helper for Android

Google Direction Library

Google Direction Library

Download

Since version 2.1.2 will move from JCenter to MavenCentral

  1. // build.gradle (project)
  2. allprojects {
  3. repositories {
  4. mavenCentral()
  5. /* ... */
  6. }
  7. }

Gradle

  1. implementation 'com.akexorcist:google-direction-library:1.2.1'

Sample Code

Simple Direction Request

  1. GoogleDirection.withServerKey("YOUR_SERVER_API_KEY")
  2. .from(LatLng(37.7681994, -122.444538))
  3. .to(LatLng(37.7749003,-122.4034934))
  4. .avoid(AvoidType.FERRIES)
  5. .avoid(AvoidType.HIGHWAYS)
  6. .execute(
  7. onDirectionSuccess = { direction: Direction? ->
  8. if(direction.isOK()) {
  9. // Do something
  10. } else {
  11. // Do something
  12. }
  13. },
  14. onDirectionFailure = { t: Throwable ->
  15. // Do something
  16. }
  17. )

Multiple Waypoints Direction Request

  1. GoogleDirection.withServerKey("YOUR_SERVER_API_KEY")
  2. .from(LatLng(41.8838111, -87.6657851))
  3. .and(LatLng(41.8766061, -87.6556908))
  4. .and(LatLng(41.8909056, -87.6467561))
  5. .to(LatLng(41.9007082, -87.6488802))
  6. .transportMode(TransportMode.DRIVING)
  7. .execute(
  8. onDirectionSuccess = { direction: Direction? ->
  9. if(direction.isOK()) {
  10. // Do something
  11. } else {
  12. // Do something
  13. }
  14. },
  15. onDirectionFailure = { t: Throwable ->
  16. // Do something
  17. }
  18. )

or

  1. val waypoints: List<LatLng> = listOf(
  2. LatLng(41.8766061, -87.6556908),
  3. LatLng(41.8909056, -87.6467561)
  4. )
  5. GoogleDirection.withServerKey("YOUR_SERVER_API_KEY")
  6. .from(LatLng(41.8838111, -87.6657851))
  7. .and(waypoints)
  8. .to(LatLng(41.9007082, -87.6488802))
  9. .transportMode(TransportMode.DRIVING)
  10. .execute(
  11. onDirectionSuccess = { direction: Direction? ->
  12. if(direction.isOK()) {
  13. // Do something
  14. } else {
  15. // Do something
  16. }
  17. },
  18. onDirectionFailure = { t: Throwable ->
  19. // Do something
  20. }
  21. )

See example code for more detail

To get API key, please read Get Google Maps Direction API Key

Demo

Try it at Google Play

ProGuard

  1. -keep class com.google.android.gms.maps.** { *; }
  2. -keep interface com.google.android.gms.maps.* { *; }
  3. -dontwarn retrofit2.**
  4. -keep class retrofit2.** { *; }
  5. -keepattributes Signature
  6. -keepattributes Exceptions
  7. -keepclasseswithmembers class * {
  8. @retrofit2.http.* <methods>;
  9. }
  10. -keep class com.akexorcist.googledirection.model.** { *;}

Change Log

See CHANGELOG.md

Licence

Copyright 2021 Akexorcist

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.