【问题标题】:Android / Google Maps API - Calculate width and height in pixel of the full MapAndroid / Google Maps API - 以像素为单位计算完整地图的宽度和高度
【发布时间】:2017-02-15 18:14:00
【问题描述】:

所以我目前正在制作基于 GoogleMaps 的游戏。因为我想制作相机,所以我需要整个谷歌地图的像素大小。

这就是我的意思:

我已经试过了:

    // 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。 sn-p有什么问题?还有其他方法可以计算谷歌地图的全尺寸吗?或者这只是返回当前显示的地图部分的大小?

【问题讨论】:

标签: java android google-maps google-maps-api-3


【解决方案1】:

基于If I call getMeasuredWidth() or getWidth() for layout in onResume they return 0,你可以让它像这样工作:

mapView = mapFragment.getView();
mapView.post(new Runnable() {
    @Override
    public void run() {
        int width = mapView.getMeasuredWidth();
        int height = mapView.getMeasuredHeight();

        String widthAndHeight = width + " " + height;
    }
});

【讨论】:

  • 感谢您的回答:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
  • 2014-12-06
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多