我正在尝试通过osmdroid编写一个地图基础应用程序,我希望当用户打开应用程序时,可以在线查看googlemaps。 我在Eclipse中编写代码,但是当我在虚拟设备上运行应用程序时,我无法看到谷歌地图 这是我的Androidmanifest文件:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />`
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.location.network" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.wifi" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.osm.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="myapikey" />
</application>
</manifest>
这是我的代码:
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapView mapView=new MapView(this, 256);
// mapView mapView = new m(this, 256);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.getController().setZoom(14);
mapView.getController().setCenter(new GeoPoint(34.638293,50.876312));
setContentView(mapView);
mapView.setUseDataConnection(false);
mapView.setTileSource(TileSourceFactory.MAPNIK);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
答案 0 :(得分:0)
尝试实施此目的:
private void setMapView() {
if (mMap != null) {
mMap.setMyLocationEnabled(false);
}
final com.google.android.maps.MapView mapView = new com.google.android.maps.MapView(this, ManifestUtil.retrieveKey(this, "com.google.android.geo.API_KEY"));
setContentView(mapView);
mMap = MapFactory.getMap(mapView);
final Position position = new Position(52.370816, 9.735936); // Hannover
position.setZoomLevel(14);
mMap.setPosition(position);
mMap.setMyLocationEnabled(false);
addMarkers();
addPolyline();
mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
@Override
public void onCameraChange(final IPosition position) {
Log.d(Constants.LOGTAG, "onCameraChange");
}
});
}
这是来自osmdroid的样本。如您所见,您需要谷歌GEO API密钥才能获得谷歌地图图块到您的应用程序。也许使用不同的地图然后谷歌地图会更好的解决方案。这是官方文档,其中列出了所有&#34;开箱即用的#34;您可以使用https://github.com/osmdroid/osmdroid/wiki/Map-Sources
的地图来源