Mapview getLatitudeSpan and getLongitudeSpan not working

后端 未结 4 831
醉梦人生
醉梦人生 2020-12-06 13:30

Sometimes when trying to get the Latitude span or Longitude span of a mapview with getLatitudeSpan() and getLongitudeSpan() I get 0 and 360*1E6 respectively. This doesn\'t h

4条回答
  •  自闭症患者
    2020-12-06 14:11

    I have been messing around with this... and having a mapview in a tabbed activity... the values are not initialized until onResume()... I verified this by putting:

            final Handler mHandler = new Handler();
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    latSpan = mapView.getLatitudeSpan();
                    lngSpan = mapView.getLongitudeSpan();
                    if ((latSpan == 0) && (lngSpan == 360000000)) {
                        count++;
                        System.out.println("here we go again! " + count);
                        mHandler.postDelayed(this, 100);
                    }       
                }
            }, 100);
    

    In Various locations... in onCreate() and onStart() it will go indefinitely (until I switch to that tab), in onResume() it gets correct values immediately.

提交回复
热议问题