[英]Android / Google Maps API - Calculate width and height in pixel of the full Map
因此,我目前正在制作一款基於GoogleMaps的游戲。 因為我想制作相機,所以我需要整個Google地圖的大小(以像素為單位)。
這是我的意思:
我已經嘗試過:
// pre generated by android studios
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
int width = mapFragment.getView().getMeasuredWidth();
int height = mapFragment.getView().getMeasuredHeight();
String widthAndHeight = width+" "+height;
但是它只返回null。 該代碼段出了什么問題? 還有其他方法可以計算Google地圖的完整大小嗎? 還是僅返回當前顯示的地圖部分的大小?
基於如果我在onResume中調用getMeasuredWidth()或getWidth()進行布局,則它們返回0 ,則可以像下面這樣工作:
mapView = mapFragment.getView();
mapView.post(new Runnable() {
@Override
public void run() {
int width = mapView.getMeasuredWidth();
int height = mapView.getMeasuredHeight();
String widthAndHeight = width + " " + height;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.