我正在嘗試使用 Kotlin 在我的 Android 應用程序中實現 DirectionsApi 以在 Google 地圖上繪制折線。我使用以下方法添加了所需的庫:implementation 'com.google.maps:google-maps-services:0.9.0'然后在我的 MapFragment 中包含以下函數:private fun getGeoContext() : GeoApiContext { val geoApiContext = GeoApiContext.Builder() .apiKey(getString(R.string.directions_apikey)) .build() return geoApiContext}最后在我的 onMapReady 中,我嘗試使用以下方法獲取路線結果:val origin = "Hotel Hillview Munnar, State Highway 16, Moolakadai, Munnar, Kerala, India"val dest = "Echo Point, Kannan Devan Hills, Kerala, India"val apiRequest = DirectionsApi.newRequest(getGeoContext()) apiRequest.origin(origin) apiRequest.destination(dest) apiRequest.mode(TravelMode.DRIVING) apiRequest.setCallback(object : com.google.maps.PendingResult.Callback<DirectionsResult> { override fun onResult(result:DirectionsResult) { Timber.i("Call Success") val routes = result.routes } override fun onFailure(e:Throwable) { } })
Google 的 DirectionsApi 似乎在 Kotlin 中不起作用
慕婉清6462132
2021-10-20 16:31:49