带有 android 和 google 地图的 TileOverlay
TileOverlay with android and google maps
我已经使用 MapTiler 创建了一些图块,我试图用 android 覆盖到 Google 地图上,但运气不佳。 Android 文档中关于这个主题的内容非常少,但我已经完成了我认为应该起作用的工作,但当我放大到正确的级别时,我没有看到这些图块。我正在尝试在 onMapReady() 回调中进行覆盖,我应该在其他地方做吗?
这是我的 onMapReady 方法代码:
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.setMyLocationEnabled(true);
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(44.481705,-114.9378269)).zoom(16).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mTileOverlay = googleMap.addTileOverlay(new TileOverlayOptions()
.tileProvider((new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = "http://www.example.com/tiles/"+zoom+"/"+x+"/"+y+".png";
// added this logging to see what the url is
Log.d("home", s);
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
})));
}
有什么想法吗?
TIA
编辑:我添加了一些日志记录以查看 's'(我的 url)返回了什么,它返回了正确的 url 并且我的服务器正在提供磁贴url 正确,但在 android.
的地图上仍然看不到任何东西
事实证明我在 getTileUrl() 方法中有一个 toast 阻止返回图像。当我删除它时,瓷砖得到了正确的服务。
我已经使用 MapTiler 创建了一些图块,我试图用 android 覆盖到 Google 地图上,但运气不佳。 Android 文档中关于这个主题的内容非常少,但我已经完成了我认为应该起作用的工作,但当我放大到正确的级别时,我没有看到这些图块。我正在尝试在 onMapReady() 回调中进行覆盖,我应该在其他地方做吗?
这是我的 onMapReady 方法代码:
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.setMyLocationEnabled(true);
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(44.481705,-114.9378269)).zoom(16).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mTileOverlay = googleMap.addTileOverlay(new TileOverlayOptions()
.tileProvider((new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = "http://www.example.com/tiles/"+zoom+"/"+x+"/"+y+".png";
// added this logging to see what the url is
Log.d("home", s);
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
})));
}
有什么想法吗?
TIA
编辑:我添加了一些日志记录以查看 's'(我的 url)返回了什么,它返回了正确的 url 并且我的服务器正在提供磁贴url 正确,但在 android.
的地图上仍然看不到任何东西事实证明我在 getTileUrl() 方法中有一个 toast 阻止返回图像。当我删除它时,瓷砖得到了正确的服务。