Introduction:
Osmdroid
ProvidesOpenStreetMap-DataInteractive tools and views. It isAndroidOfMapviewClass substitution. This document explains how to start usingOsmdroid.
Official Website:
Http://code.google.com/p/osmdroid/
Function:
Basic functions: view maps, zoom maps, single-point movement, and multi-touch
Environment:
1Set upJDKEnvironment, InstallationEclipseAndADTPlug-ins.
2, NewAndroidEngineering
3, Built in the project packageLibFolderOsmdroid-android-3.0.5.jar,Httpmine-4.0.1.jar,Appche-mine4j-0.6345035.jar,Slf4j-android-1.5.8.jarPutLibFolder.
4, Right-click the project name, and selectBuild path-> config build path, ClickJava build path-> Libraries, ClickAdd
JarsSet3FourJarAdd the package to the project.
(If the source code of the downloaded osmdroid is used, change the source code package to the SRC package of the project in Steps 3 and 4 and refresh it. We recommend that you use the source code to facilitate future changes.Code.)
5InXMLFile can be usedOrg. osmdroid. Views. mapviewAddMapviewComponent. WhereTilesource = "mapquestosm"Set the slice sourceOSM (OpenStreetMap).
6, PassFindviewbyid ()To obtainMapview. Then initialize and set the slice source, center point, and layer zoom level for it.
Permission:
You needManifestAdd the following permissions to the file:
<Uses-Permission Android: Name = "android. permission. access_coarse_location "/> <uses-Permission Android: Name =" android. permission. access_fine_location "/> <uses-Permission Android: Name =" android. permission. access_wifi_state "/> <uses-Permission Android: Name =" android. permission. access_network_state "/> <uses-Permission Android: Name =" android. permission. internet "/> <uses-Permission Android: Name =" android. permission. write_external_storage "/>
Source file:
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 geomapactivity extends activity {private mapcontroller; private mapview; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mapview = (mapview) findviewbyid (R. id. map); mapview. settilesource (tilesourcefactory. mapnik); mapview. setbuiltinzoomcontrols (true); mapcontroller = mapview. getcontroller (); mapcontroller. setzoom (15); geopoint point2 = new geopoint (51496994,-134733); mapcontroller. setcenter (point2 );}}
Layout FileMain. xml:
<? 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. mapviewandroid: Id = "@ + ID/Map" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: clickable = "true" Android: enabled = "true" tilesource = "mapquestosm"/> </relativelayout>