我正在构建使用自定义地图平铺的Android应用。我开始使用一套运行良好但只有有限缩放级别和面积的设置。然后我切换到另一个覆盖更多区域的拼贴集,但只是拒绝在Android中显示。我可以在Javascript地图中看到它们,并且LogCat中没有错误,所以我不确定发生了什么。自定义地图平铺在Chrome中工作但不是Andriod
是否只有某些Android地图叠加层支持的图像格式?
仅供参考,这里有两个瓦套:
这一件作品都在网络上,并在Android中: http://mooproductions.org/vfrs/local.html
这一件作品在网络上,但只是在Android上不会呈现: http://mooproductions.org/vfrs/national.html
下面是我使用提供瓦套他的代码:
public class VfrTileProvider extends UrlTileProvider
{
// private static final String BASE_URL = "http://www.mooproductions.org/vfrs/%d/%d/%d.png";
// private static final String BASE_URL = "http://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw/%d/%d/%d.jpg";
private static final String BASE_URL = "http://vfrmap.com/20170914/tiles/vfrc/%d/%d/%d.jpg";
public VfrTileProvider (int width, int height)
{
super(width, height);
}
@Override
public URL getTileUrl (int x, int y, int zoom)
{
int reversedY = (1 << zoom) - y - 1;
// String tileUrl = String.format(Locale.US, BASE_URL, zoom, x, reversedY);
String tileUrl = String.format(Locale.US, BASE_URL, zoom, reversedY, x);
Log.d("Tile Provider", tileUrl);
URL url = null;
try { url = new URL(tileUrl); }
catch (MalformedURLException e) { e.printStackTrace(); }
return url;
}
}
您可以看到注释掉了我使用该工作的瓦片集的其他URL。 tileUrl的创建有点不同,因为这个新的tile集将x和y转换为它们的url。
这里是我用来显示自定义瓷砖代码:
@Override
public void onMapReady (GoogleMap googleMap)
{
_map = googleMap;
_map.setMapType(GoogleMap.MAP_TYPE_NONE);
VfrTileProvider tileProvider = new VfrTileProvider(256, 256);
_map.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
Criteria criteria = new Criteria();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }, REQUEST_LOCATION_PERMISSION);
return;
}
Location location = _locationManager.getLastKnownLocation(_locationManager.getBestProvider(criteria, false));
if (location != null)
{
_map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude()))
.zoom(10)
.build();
_map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
似乎问题不在图像格式中,但在Android本机应用程序中使用自定义切片图层:似乎本机应用程序无法显示某些缩放级别的地图,如果没有切片并且不能自动跳过该图层。也许你会从缩放级别开始显示地图,没有自定义图块和Google地图引擎就停留在它上面(在没有自定义图块的缩放级别上)。另外,请添加一些源代码以更好地理解问题。 –
我为我知道有瓷砖的级别设置地图的缩放级别。我也尝试缩放通过我的服务器上的磁贴,然后退出,然后再回过头,永远不会“卡住”。 – CaseyB
事实上,我甚至在构建它们时注销这些瓷砖的网址,我可以点击它们,并在浏览器中打开它们。 – CaseyB