Replacing google maps to open street map [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this questionI'm new to this. I'm creating an android application which locates my contacts. I have tried some tutorials and it runs. but how to replace google map to open street map. I have this code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.PositionLocator.android">
<application android:icon="@drawable/icon">
<activity android:name=".PositionLocator" android:label="@string/app_name">
</activity>
<activity android:name=".PositionLocatorMap" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps"/>
</application>
<开发者_JS百科uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
</manifest>
The mapsforge library seems also very promising. Seems that they are compatible to the GoogleMaps API and that you just need to exchange imports.
Add below line:
compile 'org.osmdroid:osmdroid-android:5.6.2'
into your build.gradle(Module:app) file's dependencies.
dependencies {
//Other required dependencies
compile 'org.osmdroid:osmdroid-android:5.6.2'
}
This will include all required OSM libraries to your project.
In your xml file (map screen) replace below code with the already written Google maps code:
<!--<fragment-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="fill_parent"-->
<!--android:id="@+id/mapview"-->
<!--tools:context="MapActivity"-->
<!--android:name="com.google.android.gms.maps.SupportMapFragment"-->
<!--android:layout_below="@+id/header" />-->
<org.osmdroid.views.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:layout_below="@+id/header"
android:layout_above="@+id/layout_for_buttons"/>
Osmdroid works very well for this purpose:
http://code.google.com/p/osmdroid/
We use it in our app and don't have any drawbacks until now.
精彩评论