一、osmdroid环境配置与测试

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请前往官网或者看作者后续相关内容。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值