如何获得颤动中的估计旅行时间和距离

时间:2018-07-02 10:25:26

标签: api google-maps flutter apple-maps

我正在尝试获取用户当前位置和预定义目的地之间的估计时间和距离,但我找不到解决方法。我知道flutter现在具有地图插件-flutter maps,但我不需要显示地图,只需使用地图api计算估计的旅行时间和距离。类似于MKDirections。我想念什么吗?有什么办法吗?

1 个答案:

答案 0 :(得分:4)

您可以使用Google的Distance Matrix API并将简单的http请求发送到:

buildscript {
repositories {
jcenter()
maven {
  url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}

apply plugin: 'com.android.library'

def DEFAULT_COMPILE_SDK_VERSION             = 26
def DEFAULT_BUILD_TOOLS_VERSION             = "26.0.2"
def DEFAULT_TARGET_SDK_VERSION              = 26
def DEFAULT_SUPPORT_LIBRARY_VERSION         = "27.1.0"

android {
  compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? 
  rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
  buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? 
  rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION

  defaultConfig {
   minSdkVersion 16
   targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION

versionCode 1
versionName "1.0.0"
}
lintOptions {
abortOnError false
warning 'InvalidPackage'
}


 buildToolsVersion '27.0.3'
}

repositories {
  mavenCentral()
  maven {
  url 'https://maven.google.com'
  }
  maven { url "https://jitpack.io" }
  maven {
  // All of React Native (JS, Obj-C sources, Android binaries) is 
  installed from npm
   url "$rootDir/../node_modules/react-native/android"
 }
}

dependencies {
 def supportLibVersion = rootProject.hasProperty('supportLibVersion')  ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIBRARY_VERSION

 implementation 'com.facebook.react:react-native:0.20.1'
 implementation 'com.facebook.infer.annotation:infer-annotation:0.11.2'
 implementation "com.google.zxing:core:3.2.1"
 implementation "com.drewnoakes:metadata-extractor:2.9.1"
 implementation "com.google.android.gms:play-services-vision:15.0.2"
 implementation "com.android.support:exifinterface:27.1.1"
 implementation "com.android.support:support-annotations:$supportLibVersion"
  implementation "com.android.support:support-v4:27.1.1"
}

其中https://maps.googleapis.com/maps/api/distancematrix/json ?units=imperial &origins=40.6655101,-73.89188969999998 &destinations=40.6905615%2C,-73.9976592 &key=YOUR_API_KEY 是起点,目的地是origins点。用您的值替换它们。

对于请求,您可以使用软件包dio

ending