在使用GoogleMap Lite的ViewHolder時,作爲RecyclerView中行的一部分,我正在尋找回調以在Map準備就緒時設置引腳位置。我在下面找到了兩個函數。OnMapLoadedCallback和OnMapReadyCallback,什麼時候用哪個?
OnMapLoadedCallback:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnMapLoadedCallback?hl=en
OnMapReadyCallback:https://developers.google.com/android/reference/com/google/android/gms/maps/OnMapReadyCallback
兩個也被證明工作和使用(如下所示)。因此,如果他們有不同的行爲,應該在不同的場合使用,或者他們確實是相似的並且可以互換使用,我會感到困惑嗎?
使用OnMapLoadedCallback的:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker marker : markers) {
builder.include(marker.getPosition());
}
final CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(builder.build(), 0);
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
googleMap.moveCamera(cameraUpdate);
}
});
使用OnMapReadyCallback的:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker marker : markers) {
builder.include(marker.getPosition());
}
final CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(builder.build(), 0);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.moveCamera(cameraUpdate);
}
});
謝謝!
感謝你問我的問題,我一直在尋找同樣的:) –