rub*_*bin 15 android openstreetmap google-maps-api-3 osmdroid
嗨,大家过去一周我正在寻找教程/手册或步骤将开放街道地图包含到我的Android应用程序中.所有我发现的要么是一个功能更强大的大项目,否则很多问题都没有得到关于"如何"的正确结论......!
是否有适当的博客/网站或文件,可以更新鲜的参考.
Nic*_*ckT 16
我不知道任何教程,但这里是我为使用Osmdroid的最小例子编写的代码.
// This is all you need to display an OSM map using osmdroid
package osmdemo.demo;
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;
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.DEFAULT_TILE_SOURCE);
mMapView.setBuiltInZoomControls(true);
mMapController = (MapController) mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.osmdroid.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</LinearLayout>
---------------------------------------------------------- XML END
Include slf4j-android-1.5.8.jar and osmdroid-android-4.1.jar in the build path
(Google search for where to get them from)
*/
Run Code Online (Sandbox Code Playgroud)
请注意,您现在必须使用最新版本(4.1)以避免阻止从OSM下载切片.
还要注意他们正在将他们的存储库移动到Github并且该过程尚未完成.此页面下载包含jar的链接
这个OSMdroid示例项目绝对是我遇到过的最简单的.启动和运行不超过5分钟.注意清单文件.
为了更复杂一点,本教程显示了一个包含当前地点点的地图.
你应该下载OSMdroid和SLF4J,放在libs文件夹,Add as Libraryosmdroid中,用适当的权限修复AndroidManifest.xml(参见第一篇教程).如果这样做,则无需gradle.build按照第一个教程中的建议更改文件.
我建议您在使用这些时使用旧版本的osmdroid(3.x)作为初学者.一旦感到舒服,请迁移到较新版本的osmdroid(4.x或5.x).
GeoPoint和MapController类在较新版本中更改名称,因此请注意INCOMPATIBLE TYPES ERROR
IGeoPoint无法转换为GeoPoint
IMapController无法转换为MapController
| 归档时间: |
|
| 查看次数: |
23827 次 |
| 最近记录: |