3

I'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>
<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> 
4

3 回答 3

5

mapsforge似乎也很有前途。似乎它们与 GoogleMaps API 兼容,您只需要交换导入即可。

于 2011-02-15T11:41:54.267 回答
1

添加以下行:

compile 'org.osmdroid:osmdroid-android:5.6.2'

进入您的 build.gradle(Module:app) 文件的依赖项。

dependencies {
    //Other required dependencies
    compile 'org.osmdroid:osmdroid-android:5.6.2'
}

这将包括项目所需的所有 OSM 库。

在您的 xml 文件(地图屏幕)中,将以下代码替换为已编写的 Google 地图代码:

<!--<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"/>
于 2017-08-18T11:23:31.600 回答
0

Osmdroid 非常适合这个目的:

http://code.google.com/p/osmdroid/

我们在我们的应用程序中使用它,直到现在还没有任何缺点。

于 2013-02-08T10:31:19.923 回答