Osmdroid源码编译

源码官方地址

编译源码

官方编译方法:

  • Checkout the osmdroid source from git to a local folder.
    使用git下载源码
    git clone https://github.com/osmdroid/osmdroid.git
  • Navigate to the osmdroid folder and run the command
    下载完之后进入下载的osmdroid目录执行下面的命令,如果命令not found 则需要配置git环境变量,或者在命令前面添加 ./
    gradlew clean install.
    This will also install to your local maven repository.
  • To run tests against a device or avd,
    运行测试
    run gradlew cC
  • 使用Android Studio 导入项目

根据官方的编译方法发现总是卡住,即使翻墙了也无济于事。就用下面的笨办法编译了一下,简单介绍一下,osmdroid-android和osmdroid-third-party是Library,在项目中我想用osmdroid的引擎加载google的地图,所以需要用到这两个库。

  • 新建 android Library,将osmdroid-android目录下的main文件夹直接拷贝到新建Library对应的目录下,删除原本的main目录。
  • osmdroid-third-party的操作同上,但要注意一点,third-party需要用到谷歌map的api,所以需要用google apis进行编译。
    • 两个Library建完之后就可以引入自己真正的项目
compile project(':osmdroid-android')
compile project(':osmdroid-third-party')

简单展示一下地图
布局中添加mapview控件,导包不要导错了,是org下的mapview

<org.osmdroid.views.MapView
        android:id="@+id/map"
        tilesource="MapquestOSM"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:enabled="true" />

代码实例化

 mMapView = (MapView) findViewById(R.id.map);
 mController = mMapView.getController();
 mMapView.setTileSource(TileSourceFactory.MAPNIK);
 mMapView.setBuiltInZoomControls(true);
 mMapView.setMultiTouchControls(true);
 GeoPoint center = new GeoPoint(39.901873, 116.326655);
 //地图是通过controller控制中心点的
 mController.setCenter(center);
 mController.setZoom(12);

效果

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值