gpt4 book ai didi

Android:Google MapView 在加载 map 时显示进度指示器

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:53:25 25 4
gpt4 key购买 nike

有没有办法监听 MapView还在加载吗?因为我想在 MapView 下载 map 图 block 时显示进度指示器(例如沙漏)。

有什么解决办法吗?

最佳答案

您可以使用 OnCameraChangeListenerOnMapLoadedCallback 来模拟此行为。

来自 the documentation GoogleMap.OnCameraChangeListener 的:

public abstract void onCameraChange (CameraPosition position)

Called after the camera position has changed. During an animation, this listener may not be notified of intermediate camera positions. It is always called for the final position in the animation.

This is called on the main thread.

来自 the documentation GoogleMap.OnMapLoadedCallback:

public abstract void onMapLoaded ()

Called when the map has finished rendering. This will only be called once. You must request another callback if you want to be notified again.

如那里所述,onMapLoaded() 只会被调用一次,因此策略可以是每次 onCameraChange GoogleMap.OnMapLoadedCallback 被调用。

这是一个(非常简单的)示例来说明答案:

public class MapsActivity extends FragmentActivity implements OnCameraChangeListener, OnMapLoadedCallback {
private GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();

googleMap.setOnCameraChangeListener(this);
}

@Override
public void onMapLoaded() {
//TODO: Hide your progress indicator
}

@Override
public void onCameraChange(final CameraPosition cameraPosition) {
googleMap.setOnMapLoadedCallback(this);

//TODO: Show your progress indicator
}
}

关于Android:Google MapView 在加载 map 时显示进度指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12192782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com