一、osmdroid环境配置与测试

来源:互联网 发布:c语言中的标识符 编辑:程序博客网 时间:2024/06/16 07:19

osmdroid环境配置与测试

osmdroid可用于是一款完全免费的用于替换Android MapView类的开源包。它包含了一个模块化的瓦片提供系统,用于支持多种类型的在线和离线瓦片资源,并且内置的覆盖物支持绘图图标、跟踪位置及绘制图形。

当前发布版本:5.6.5 2017/02/04

环境配置

  • Gradle dependency

    在你的项目build.gradle(Module:app)中添加如下配置:

    repositories {    mavenCentral()}dependencies {     compile 'org.osmdroid:osmdroid-android:5.6.4'}
  • Maven dependency

    在你的配置文件中加入:

    <dependency>  <groupId>org.osmdroid</groupId>  <artifactId>osmdroid-android</artifactId>  <version>5.6.4</version>  <type>aar</type></dependency>

环境测试

在布局文件中添加MapView:

<?xml version="1.0" encoding="UTF-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="fill_parent"      android:layout_height="fill_parent" >          <org.osmdroid.views.MapView              android:id="@+id/myOSMmapview"              android:layout_width="match_parent"              android:layout_height="match_parent"              tilesource="MapquestOSM"              android:clickable="true"              android:enabled="true" >          </org.osmdroid.views.MapView>  </RelativeLayout>  

在相应Activity的 onCreate() 方法中添加如下代码:

    mMapView = (MapView) findViewById(R.id.myOSMmapview);      mController = mMapView.getController();      //ResourceProxy init      mResourceProxy = new DefaultResourceProxyImpl(this);      mMapView.setTileSource(TileSourceFactory.MAPNIK);      mMapView.setBuiltInZoomControls(true);      mMapView.setMultiTouchControls(true);      //定位当前位置,北京市西长安街复兴路      GeoPoint center = new GeoPoint(39.901873, 116.326655);      mController.setCenter(center);      mController.setZoom(14);

效果图如下:

osmdroid效果图

上文引用至osmdroid官网,测试代码参考至csdn。关于如何使用osmdroid请前往官网或者看作者后续相关内容。