3

This is my first post here, so I hope I'll explain my problem clear enough:

I'm extending the FragmentActivity class to create a HeatMapActivity. In this activity I use a GoogleMap object, which I obtain as follows:

// Try to obtain the map from the SupportMapFragment.
map = ((SupportMapFragment) getSupportFragmentManager()
      .findFragmentById(R.id.heatmap)).getMap();

Now, after doing a null-Check etc., I'm adding a TileOverlay in the setUpMap() method, as shown below:

// Configure and add overlay
tileProvider = new HeatMapTileProvider(map);
map.addTileOverlay(new TileOverlayOptions()
      .tileProvider(tileProvider));

Ok, so far no problem at all. I implemented the TileProvider interface to provide the tiles for the HeatMap overlay.

I want to use the Projection object for converting latitude/longuitude to and from pixels on the screen. The Projection object should be returned by the getProjection() method of the GoogleMap class.

So now here's the problem: If I use the following code in the HeatMapActivity class, everything is fine:

System.err.println("Test1: " + map.getProjection().fromScreenLocation(new Point(50,  50)));

But if I forward the GoogleMap object to the TileProvider, respectively to the renderer I use, the code is not working anymore:

public byte[] render(int x, int y, int zoom, GoogleMap map) {
  ...
  System.err.println("Test2: " + map);
  System.err.println("Test3: " + map.getProjection().fromScreenLocation(new Point(50,  50)));
  ...
}

I definitely know, that the map parameter is not null (see Test 2), but the code just seems to block when I call getProjection(). There is no error coming up and if I don't use the Projection object, everything else is working fine. I don't have any clue, why I should not be allowed to call getProjection() from another class than the activity...

I am using the ADT bundle for Windows (version x86_64-20130729), Android SDK version from 8 to 17, testing on Android 2.3.5 at the moment. The map is displayed, the needed libraries are included and the permissions are set in the android manifest.

Any ideas? Any help or hints are appreciated.

Seb

4

1 回答 1

2

这里的问题是getTile(和你的render方法)在 UI 线程之外被调用。
这将导致您看不到的异常,因为它可能由调用getTile. 这真的很糟糕,它不会崩溃,所以有人可以在 gmaps api 问题上发布问题。
尝试将调用包装到getProjectiontry-catch 中以查看它。

因为您不应该与主线程外部进行交互GoogleMap,所以您将不得不找到另一种实现方式,您想要实现的......

无论如何,我可以想象没有充分的理由需要打电话getProjectiongetTile也许另一个描述你真正问题的问题?

于 2013-09-02T19:12:56.800 回答