替换谷歌地图以打开街道地图

时间:2011-02-04 14:42:06

标签: android eclipse google-maps openstreetmap

我是新手。我正在创建一个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> 

3 个答案:

答案 0 :(得分:5)

mapsforge library似乎也很有希望。似乎它们与GoogleMaps API兼容,您只需要交换导入。

答案 1 :(得分: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"/>

答案 2 :(得分:0)

Osmdroid非常适用于此目的:

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

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

相关问题