Android MapView Tiles Empty

时间:2014-02-11 18:37:32

标签: android maps

我正在尝试根据用户的位置显示城市地图,可以在线和离线使用(如果信号很差)。出于某种原因,我可以显示mapview,但我只是得到一个空白的瓷砖空白屏幕。

有没有想过为什么会这样?

什么是热门片段

MyItemizedOverlay myItemizedOverlay = null;
    MyLocationOverlay myLocationOverlay = null;
    MapController myMapController = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_whats_hot, container, false);

        final MapView mapView = (MapView) rootView.findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
        int markerWidth = marker.getIntrinsicWidth();
        int markerHeight = marker.getIntrinsicHeight();
        marker.setBounds(0, markerHeight, markerWidth, 0);

        // save zip to sd
        AssetManager assetManager = getActivity().getAssets();
        InputStream is;
        String fileName = "map_new_haven.zip";    // the zip file lies in assets root
        String path = this.getActivity().getExternalFilesDir(null) + File.separator + fileName; // the path I save SD to

        File tileFile = new File(path);
        if(!tileFile.exists()) {
            try {
                is = assetManager.open(fileName);

                FileOutputStream fo = new FileOutputStream(path);

                byte[] b = new byte[1024];
                int length;
                while((length = is.read(b)) != -1) {
                    fo.write(b, 0, length);
                }

                fo.flush();
                fo.close();
                is.close();
            } catch (IOException  e) {
                e.printStackTrace();
            }
        }

        IArchiveFile[] archives = new IArchiveFile[1];
        archives[0] = ArchiveFileFactory.getArchiveFile(tileFile);

        // Simple implementation that extends BitmapTileSourceBase and nothing else
        ITileSource customTiles = new XYTileSource("MapQuest", null, 10, 14, 256, ".jpg");  // MapQuest is the name of the folder inside the zip (so zip is map.zip and inside it is a folder called MapQuest)

        MapTileModuleProviderBase[] providers = new MapTileModuleProviderBase[2];
        providers[0] = new MapTileFileArchiveProvider(new SimpleRegisterReceiver(getActivity().getApplicationContext()), customTiles, archives);    // this one is for local tiles (zip etc.)
        providers[1] =  new MapTileDownloader(TileSourceFactory.MAPNIK);    // MAPNIK web tile source

        mapView.setUseDataConnection(true);

        MapTileProviderArray tileProvider = new MapTileProviderArray(customTiles, 
                new SimpleRegisterReceiver(getActivity().getApplicationContext()), providers);
        TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, getActivity().getApplicationContext());
        tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);  // this makes sure that the invisble tiles of local tiles are transparent so we can see tiles from web, transparent have a minor performance decline.

        mapView.getOverlays().add(tilesOverlay);

        mapView.invalidate();

        myLocationOverlay = new MyLocationOverlay(getActivity(), mapView);
        mapView.getOverlays().add(myLocationOverlay);

        myMapController = mapView.getController();
        myMapController.setZoom(3);

        ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(getActivity());
        mapView.getOverlays().add(myScaleBarOverlay);

        myLocationOverlay.runOnFirstFix(new Runnable() {
            public void run() {
             mapView.getController().animateTo(myLocationOverlay.getMyLocation());
               } 
           });

        return rootView;
    }

MyItemizedOverlay

public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {

 private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();

 public MyItemizedOverlay(Drawable pDefaultMarker,
   ResourceProxy pResourceProxy) {
  super(pDefaultMarker, pResourceProxy);
  // TODO Auto-generated constructor stub
 }

 public void addItem(GeoPoint p, String title, String snippet){
  OverlayItem newItem = new OverlayItem(title, snippet, p);
  overlayItemList.add(newItem);
  populate(); 
 }

 @Override
 public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3) {
  // TODO Auto-generated method stub
  return false;
 }

 @Override
 protected OverlayItem createItem(int arg0) {
  // TODO Auto-generated method stub
  return overlayItemList.get(arg0);
 }

 @Override
 public int size() {
  // TODO Auto-generated method stub
  return overlayItemList.size();
 }

}

我很确定该文件位于我指定的文件夹中,我尝试在互联网连接模式和飞行模式(离线)上运行此文件。两者都显示了mapview,但只是空白的白色瓷砖。

Blank Tiles

logcat的

02-11 13:41:23.343: D/libc(26293): [NET] getaddrinfo+,hn 14(0x3139322e313633),sn(),family 0,flags 4
02-11 13:41:23.343: D/libc(26293): [NET] getaddrinfo-, SUCCESS
02-11 13:41:23.343: D/libc(26293): [NET] getaddrinfo+,hn 22(0x74696c652e6f70),sn(),family 0,flags 4
02-11 13:41:23.343: D/libc(26293): [NET] getaddrinfo-,err=8
02-11 13:41:23.343: D/libc(26293): [NET] getaddrinfo+,hn 22(0x74696c652e6f70),sn(),family 0,flags 1024
02-11 13:41:23.343: D/libc(26293): [NET] getaddrinfo-, 1
02-11 13:41:23.343: D/libc(26293): [NET] getaddrinfo_proxy+
02-11 13:41:23.353: D/libc(26293): [NET] getaddrinfo_proxy-, success
02-11 13:41:23.353: I/global(26293): call createSocket() return a new socket.
02-11 13:41:23.353: D/libc(26293): [NET] getaddrinfo+,hn 14(0x3139322e313633),sn(),family 0,flags 4
02-11 13:41:23.353: D/libc(26293): [NET] getaddrinfo-, SUCCESS
02-11 13:41:23.453: W/org.osmdroid.tileprovider.modules.MapTileDownloader(26293): Problem downloading MapTile: /3/3/3 HTTP response: HTTP/1.1 403 Forbidden

0 个答案:

没有答案