我想在谷歌地图加载后做一些事情(maptiles已被填充)无论如何可以实现这一点吗?
正如所指出的qubz https://stackoverflow.com/users/496625/qubz,ViewTreeObserver可用于实现地图加载完成后的回调,因此用户将得到例如启动后正确位置:
@Override
public void onCreate(Bundle savedInstanceState) {
// This is a small hack to enable a onMapLoadingCompleted-functionality to the user.
final View mapView = getSupportFragmentManager().findFragmentById(R.id.google_map_fragment).getView();
if (mapView.getViewTreeObserver().isAlive()) {
mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
// We use the new method when supported
@SuppressLint("NewApi")
// We check which build version we are using.
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
// Send notification that map-loading has completed.
onMapFinishedLoading();
}
});
}
}
protected void onMapFinishedLoading() {
// Do whatever you want to do. Map has completed loading at this point.
Log.i(TAG, "Map finished loading.");
GoogleMap mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.google_map_fragment))
.getMap();
mMap.moveCamera(CameraUpdateFactory.zoomIn());
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)