2012-04-15 170 views
0

我想使用osmDroid映射api与脱机和联机功能来开发android映射应用程序,但是我找不到有关它的许多教程,所以如果任何人有任何指向使用osmdroid映射的教程的链接api离线或在线。 我已经写了一个小应用程序只是为了显示从默认提供商的地图,但应用程序运行,但没有地图显示(只有squers)出了什么问题?代码:使用osmDroid映射API的android映射

MapView map = new MapView(this, 256); 
    map.setClickable(true); 
    map.setBuiltInZoomControls(true); 
    setContentView(map); 

控件显示!!!!!!

回答

1

或许缺少INTERNET(或其他)在manifest文件权限?

HowToUseJar

+1

谢谢,是的,我添加了许多其他权限,我发现人们说他们是必需的,并且所有权限都是: <使用权限android:name =“android.permission.WRITE_EXTERNAL_STORAGE”/> – 2012-04-16 09:49:12

1

它可能缺少一个瓷砖来源。下面的代码示例最小的我将使用osmdroid告诉你一个OSM地图:

import org.osmdroid.tileprovider.tilesource.TileSourceFactory; 
import org.osmdroid.util.GeoPoint; 
import org.osmdroid.views.MapController; 
import org.osmdroid.views.MapView; 
import android.app.Activity; 
import android.os.Bundle; 

// This is all you need to display an OSM map using osmdroid 
public class OsmdroidDemoMap extends Activity { 

    private MapView   mMapView; 
    private MapController mMapController; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
      setContentView(R.layout.osm_main); 
     mMapView = (MapView) findViewById(R.id.mapview); 
     mMapView.setTileSource(TileSourceFactory.MAPNIK); 
     mMapView.setBuiltInZoomControls(true); 
     mMapController = mMapView.getController(); 
     mMapController.setZoom(13); 
     GeoPoint gPt = new GeoPoint(51500000, -150000); 
     //Centre map near to Hyde Park Corner, London 
     mMapController.setCenter(gPt); 

    } 
} 
/* HAVE THIS AS YOUR osm_main.xml 
---------------------------------------------------------- XML START 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <org.osmdroid.views.MapView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/mapview" 
     ></org.osmdroid.views.MapView> 
</LinearLayout> 
---------------------------------------------------------- XML END 
Include slf4j-android-1.5.8.jar and osmdroid-android-3.0.5.jar in the build path 
(Google search for where to get them from) 
*/ 
+0

谢谢,我添加了TileSource语句到我的代码和应用程​​序仍然工作,因为它(没有错误,但没有地图显示只有正方形),并且出现在DDMS中的错误是: – 2012-04-16 08:32:31

+0

[2012-04 -16 11时24分27秒 - DDMS]空 显示java.lang.NullPointerException \t在com.android.ddmlib.Client.sendAndConsume(Client.java:573) \t在com.android.ddmlib.HandleHello.sendHELO(HandleHello的.java:142) \t在com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) \t在com.android.ddmlib.Client.getJdwpPacket(Client.java:672) \t在com.android。 ddmlib.Mon itorThread.processClientActivity(MonitorThread.java:317) \t at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263) – 2012-04-16 08:33:56

+0

谢谢,是的,我添加了许多其他权限,我发现人们说他们是必需的,所有的权限是: <使用权限android:name =“android.permission.ACCESS_COARSE_LOCATION”/> <使用权限android:name =“android.permission .ACCESS_FINE_LOCATION“/> <使用权限android:name =”android.permission.ACCESS_NETWORK_STATE“/> <使用权限android:name =”android.permission.ACCESS_WIFI_STATE“/> <使用权限android:name = “android.permission.WRITE_EXTERNAL_STORAGE”/> – 2012-04-16 09:51:35

0

您还需要

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

添加到您的清单。 Osmdroid尝试缓存切片并在没有存储访问时失败。

+0

rechengehirn:我已经写了所有必需的权限,包括这一个。 – 2013-05-27 13:50:18