替换谷歌地图为开放街图。

3

我是新手。我正在创建一个用于定位我的联系人的Android应用程序。我尝试了一些教程并且正在运行中。但是如何将谷歌地图替换为开放街道地图呢?这是我的代码:

<?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> 

1
那么,你的问题/疑问到底是什么? - Adinia
@adinia,我该如何将谷歌地图替换为OpenStreet地图? - gutentag
3个回答

5

Mapsforge库似乎也非常有前途。看来它们与GoogleMaps API兼容,只需要更换导入即可。


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"/>

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接