OSMDroid :一个设计用于完全替换 Android 内部的 MapView 类库
来源:互联网 发布:杭州认知网络 招聘 编辑:程序博客网 时间:2024/06/07 22:57
OSMDroid 设计用于完全替换 Android 内部的 MapView 类,包含一个模块化的地图拼图,支持在线和离线地图以及覆盖地图,支持标注图标、位置跟踪和绘制形状。地图引擎使用 OpenStreetMap
使用
环境:
1、搭建好JDK环境,安装eclipse和ADT插件。
2、新建android工程
3、在工程包内建lib文件夹,将osmdroid-android-3.0.5.jar、httpmine-4.0.1.jar、appche-mine4j-0.6345035.jar、slf4j-android-1.5.8.jar放入lib文件夹。
4、在工程名上右键单击,选择Build Path->Config Build Path,单击Java Build Path->Libraries,点击Add JARs将3中的四个jar包加入到工程中。
(如果是下载的osmdroid源码,则3、4两步改为:将源码包放入工程src包下,刷新。建议使用源码,这样便于以后更改代码。)
5、在XML文件中可以使用org.osmdroid.views.MapView增加MapView组件。其中tilesource=”MapquestOSM”为地图设置切片源为OSM(OpenStreetMap)。
6、通过findViewById()来获得MapView的引用。然后初始化,为其设置切片源、中心点、图层放大级别。
权限:
你需要在Manifest文件中增加下列权限许可:
源文件:
布局文件main.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns: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/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
tilesource="MapquestOSM"/>
</RelativeLayout>
项目地址 http://code.google.com/p/osmdroid/