图形页面getLatitudeSpan和getLongitudeSpan不工作图形、页面、工作、getLatitudeSpan

2023-09-12 10:05:16 作者:╰→檛鰣吥莣ˇ

试图让纬度跨度MapView类或经度跨度getLatitudeSpan()和getLongitudeSpan()有时候,我分别得到0和360 * 1E6。这并不总是发生,但是这是一个问题,有没有人有这个问题吗?任何解决办法?我试着用getProjection()太多,但我得到了同样的问题。这里是一片code:

 图形页面图形页面=(图形页面)findViewById(R.id.mapview);
INT纬度= mapView.getLatitudeSpan(); //有时会返回0
INT长= mapView.getLongitudeSpan(); //有时会返回360 * 1E6
 

解决方案

我会检测出这一状况并安排你下班后几百毫秒再试一次。 AFAIK,这些值将最终成为可用的,但它们可能是相当与时间相关的。从理论上讲,它们应该被计算所设置的中心,并设置变焦之后,但我怀疑,他们真的没有被计算后才图形页面被渲染,并可能直到从网上的一些地图数据下载。

所以,隔离你的code,它依赖于这些跨越到一个方法。调用来自的onCreate()和方法的AsyncTask ,可能是因为你正在做的今天。但是,增加检测逻辑查找无效的值,然后调用 postDelayed()图形页面(或一些其他查看)后几百毫秒再次调用你的方法,如果值是无效的。您可能还需要添加某种计数器,所以你不这样做 postDelayed()的东西下去。

当然,

这,是一个黑客。但是,随着谷歌地图组件不是开源的,这是很难拿出一些更加牢固。

好消息,医保个人业务可以网上办理了

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 happen always but it is a problem, has anybody got this problem? Any workarounds? I tried using getProjection() too but I get the same problem. Here is the piece of code:

MapView mapView = (MapView) findViewById(R.id.mapview);
int lat = mapView.getLatitudeSpan(); // sometimes returns 0
int long = mapView.getLongitudeSpan(); // sometimes returns 360*1E6

解决方案

I would detect the condition and schedule your work to try again after a few hundred milliseconds. AFAIK, those values will eventually become available, but they may be rather timing-dependent. In theory, they should be calculated after you have set the center and set the zoom, but I suspect that they really aren't being calculated until after the MapView is rendered, and possibly not until some map data from the Internet is downloaded.

So, isolate your code that depends on those spans into a method. Call that method from onCreate() and the AsyncTask, probably as you're doing today. But, add detection logic to find the invalid values, then call postDelayed() on your MapView (or some other View) to invoke your method again after a few hundred milliseconds if the values are invalid. You may also need to add some sort of counter so you don't do this postDelayed() stuff indefinitely.

This, of course, is a hack. But, with the Google Maps component not being open source, it is difficult to come up with something more solid.