2017-09-05 147 views
0

我有一個要求,建立一個像標記,折線,多邊形和一些點擊監聽器選項的android地圖應用程序。該應用程序不能使用谷歌API,而是可以使用OSM數據。我有一個自定義瓷磚服務器,並尋找它在應用程序中的集成。我遇到了同樣提供我需要的Mapquest。我只需要知道我是否可以將自己的磁貼服務器與它整合在一起。任何幫助將不勝感激優點和缺點mapquest android

+2

請閱讀[問問]。如果您對當前的代碼有特定的問題,請詢問具體問題。如果您當前的代碼完全按照其應用的原則工作,並希望使其效率更高,請將其呈現給[代碼審閱](http://codereview.stackexchange.com/)上的審閱者。如果你期望人們爲你寫,那麼你在錯誤的網站。這是我們互相幫助的地方,但我們不會爲你做。有關Stack Overflow的更多信息,可以查看[About]。另外,請查看[mcve]以瞭解如何爲您的問題提供示例。 – Mike

回答

2

Mapquest使用OSMdroid無縫地集成爲底圖。話雖如此,它需要一個關鍵的工作。以下是我的底圖切換器(它接收底圖的索引並相應切換)。您可以選擇很容易地在底圖之間切換:

public boolean mapTileServerSwap() { 
    boolean flagOK = false; 
    String[] urlArray = {""}; 
    int mapTileServer = SessionPreferences.mapTileServer; 
    switch (mapTileServer) { 
     case(0): 
     default: 
      mapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); 
      flagOK = true; 
      break; 
     case(1): 
      urlArray[0] = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/"; 
      mapView.setTileSource(new OnlineTileSourceBase("ArcGIS Online", null, 0, 18, 256, "", 
        urlArray) { 
       @Override 
       public String getTileURLString(MapTile aTile) { 
        String mImageFilenameEnding = ".png"; 
        return getBaseUrl() + aTile.getZoomLevel() + "/" + aTile.getY() + "/" + aTile.getX() 
          + mImageFilenameEnding; 
       } 
      }); 
      flagOK = true; 
      break; 
     case(2): 
      urlArray[0] = "http://basemap.nationalmap.gov/ArcGIS/rest/services/USGSTopo/MapServer/tile/"; 
      mapView.setTileSource(new OnlineTileSourceBase("USGS Topo", null, 0, 18, 256, "", 
        urlArray) { 
       @Override 
       public String getTileURLString(MapTile aTile) { 
        String mImageFilenameEnding = ".png"; 
        return getBaseUrl() + aTile.getZoomLevel() + "/" + aTile.getY() + "/" + aTile.getX() 
          + mImageFilenameEnding; 
       } 
      }); 
      flagOK = true; 
      break; 
     case(3): 
      mapView.setTileSource(TileSourceFactory.MAPQUESTAERIAL); 
      flagOK = true; 
      break; 
     case(4): 
      mapView.setTileSource(TileSourceFactory.MAPQUESTOSM); 
      flagOK = true; 
      break; 
     case(5): 
      //TODO 20160509 
      // fix copyright and attributions for STAMEN! 
      urlArray[0] = "http://a.tile.stamen.com/watercolor/"; 
      mapView.setTileSource(new XYTileSource("Stamen WaterColor", null, 0, 18, 256, ".jpg", 
        urlArray)); 
      flagOK = true; 
      break; 
     case(6): 
      urlArray[0] = "http://a.stamen.com/terrain/"; 
      mapView.setTileSource(new XYTileSource("Stamen Terrain", null, 0, 18, 256, ".jpg", 
        urlArray)); 
      flagOK = true; 
      break; 
    } 
    return flagOK; 
} 
+0

我的瓷磚服務器是在XYZ.png格式例如: http://tile.openstreetmap.org/{z}/{x}/{y}.png「我需要與我的應用程序集成我已附加我的代碼與您在上面的實現在這裏:https://drive.google.com/open?id=0ByXacZESDmJRTzdKWjR6WG5aQW8。幫助我,謝謝! – himagaran

+0

那麼問題是什麼?XYZ格式是osmdroid中的標準格式。 – scai

+0

@scai我實際上需要知道如何將我的磁貼服務器鏈接到我的源代碼中,而不是使用mapquest – himagaran