【问题标题】:android mapview custom tileandroid mapview 自定义图块
【发布时间】:2011-06-15 03:25:05
【问题描述】:

我需要将自定义基础图层添加到我的地图视图中。我的理解是地图图块与谷歌图块完全相同。它们是以下列格式提供的静态文件:http:///tilecache///.png

例如,http:///tilecache/6/16/26.png 是佛罗里达州阿拉巴马州和密西西比州之间的墨西哥湾沿岸。

如何使用图块创建叠加层?

【问题讨论】:

    标签: android android-mapview tile


    【解决方案1】:

    osmdroid(如上所述)很酷但非常庞大。前段时间我决定改用http://sourceforge.net/projects/libwlocate/ - 它包含显示/滚动/缩放地图的功能,例如 osmdroid,但您可以选择使用 OSM、谷歌地图或谷歌卫星视图。

    如何使用它的示例可以在http://libwlocate.git.sourceforge.net/git/gitweb.cgi?p=libwlocate/libwlocate;a=blob;f=master/android/LocDemo/src/com/vwp/locdemo/LocDemo.java;h=5e2134fb7d197258f5f4f6f9021d2fa9ad9f2d9a;hb=HEAD中找到

    【讨论】:

      【解决方案2】:

      我建议使用osmdroid。您可以扩展 OnlineTileSourecBase。

      public class YourTileSource extends OnlineTileSourceBase implements IStyledTileSource<Integer> {
      
      public YourTileSource (String aName, string aResourceId,
          int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels,
          String aImageFilenameEnding, String aBaseUrl) {
          super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
                  aImageFilenameEnding, aBaseUrl);
      }
      
      public void setStyle(Integer style) {
          // TODO Auto-generated method stub
      }
      
      public void setStyle(String style) {
          // TODO Auto-generated method stub
      }
      
      public Integer getStyle() {
          // TODO Auto-generated method stub
          return null;
      }
      
      @Override
      public String getTileURLString(MapTile aTile) {
          return getBaseUrl() + "/" + aTile.getX() + "/" + aTile.getY() + "/" + aTile.getZoomLevel() + ".png";
      }
      

      }

      然后将您的图块源添加到您的地图视图:

      TileSourceFactory.addTileSource(new YourTileSource ("YourTileSource", null, 1, 20, 256, ".png", "http:///tilecache/"));
      mapView.setTileSource(TileSourceFactory.getTileSource("YourTileSource"));
      

      您的 mapView 需要是 org.osmdroid.views.MapView 才能工作。 OSMdroid 类应该替换所有的谷歌地图类。

      首先下载osmdroid-android-3.0.8.jar文件,将其添加到你项目中的libs文件夹中,然后通过右键>属性>Java构建路径>库>添加jar将其添加到项目中,然后在libs 文件夹。如果您有更多问题,请发布更多问题,我对 osmdroid 有很多经验。

      【讨论】:

        【解决方案3】:

        对于较新版本的 OSMDroid,构造函数的 aResourceId 参数已被删除,最后一个参数 aBaseUrl 是一个 String[]

        public YourTileSource (String aName, 
            int aZoomMinLevel, 
            int aZoomMaxLevel, 
            int aTileSizePixels,
            String aImageFilenameEnding, 
            String[] aBaseUrl) {
        
            super(aName, 
                  aZoomMinLevel, 
                  aZoomMaxLevel, 
                  aTileSizePixels, 
                  aImageFilenameEnding, 
                  aBaseUrl);
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-10-14
          • 1970-01-01
          • 1970-01-01
          • 2013-04-12
          • 2019-01-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多