Android的GOOGLEMAPS 2版完成加载事件或回调 [英] Android googlemaps v2 finish loading event or callback
本文介绍了Android的GOOGLEMAPS 2版完成加载事件或回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想谷歌地图加载(maptiles已经满)后做什么反正有实现的?
I want to do something after the google maps has loaded(maptiles have been filled) is there anyway to achieve that?
推荐答案
正如 qubz 指出的那样,ViewTreeObserver可用于实现回调地图的装载完成之后,因此,用户将获得如正确的位置后立即启动:
As noted by qubz, the ViewTreeObserver can be used to achieve a callback after the loading of the map has completed, so the user will get e.g. the correct location right after start-up:
@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());
}
这篇关于Android的GOOGLEMAPS 2版完成加载事件或回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文