我想使用谷歌地图创建两点的方向。 如果设置了源点,我希望在 Logcat 中看到 aaaaabbbbb 消息。 但我看不出来。
有人可以告诉我吗?
// Initialize the AutocompleteSupportFragment
val autoCompleteFragment_s = supportFragmentManager.findFragmentById(R.id.autocomplete_fragment_source) as AutocompleteSupportFragment
val autoCompleteFragment_d = supportFragmentManager.findFragmentById(R.id.autocomplete_fragment_destination) as AutocompleteSupportFragment
// Specify the types of place data to return
autoCompleteFragment_s.setPlaceFields(mutableListOf(Place.Field.ID, Place.Field.NAME))
autoCompleteFragment_d.setPlaceFields(mutableListOf(Place.Field.ID, Place.Field.NAME))
Log.i(javaClass.simpleName,"aaaaa")
// Set up a PlaceSelectionListener to handle the response.
autoCompleteFragment_s.setOnPlaceSelectedListener(object: PlaceSelectionListener {
override fun onPlaceSelected(place: Place){
Log.i(javaClass.simpleName, "aaaaabbbbb")
Log.i(javaClass.simpleName, "Place: " + place.getName() + ", " + place.getId())
val latLngDest = LatLng(10.311794, 123.915863)
googleMap!!.addMarker(MarkerOptions().position(latLngDest).title("Ehime City"))
}
override fun onError(status: Status) {
Log.i(javaClass.simpleName, "aaaaabbbbb")
Log.i(javaClass.simpleName, "An error occurred: " + status)
}
})
使用此方法将地图缩放到该位置:
public void animateMapCamera(LatLng point, int zoom) {
if (googleMap != null) {
CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(point, zoom);
googleMap.animateCamera(cu);
}
}
override fun onPlaceSelected(place: Place){
Log.i(javaClass.simpleName, "aaaaabbbbb")
Log.i(javaClass.simpleName, "Place: " + place.getName() + ", " + place.getId())
val latLngDest = LatLng(10.311794, 123.915863)
googleMap!!.addMarker(MarkerOptions().position(latLngDest).title("Ehime City"))
animateMapCamera(latLngDest, 17);
}