2011-02-04 83 views
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 2011-02-04 14:47:00

+0

@adinia如何將Google地圖替換爲openstreet地圖。 – gutentag 2011-02-04 14:52:03

回答

3

我沒有聽說過開放街道地圖到現在爲止,但一個簡單的搜索讓我到他們的頁面,在這裏你可以找到API它。

另外,here你可以看看一些實現開放式街道地圖的Android應用程序的代碼。

5

mapsforge library似乎也非常有前途。似乎它們與GoogleMaps API兼容,並且您只需交換導入。

0

添加下面一行:

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

到您的build.gradle(模塊:應用程序)文件的依賴。

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

這將包括項目所需的所有OSM庫。

在XML文件中(地圖畫面)與已經書面谷歌地圖的代碼替換下面的代碼:

<!--<fragment--> 
<!--android:layout_width="fill_parent"--> 
<!--android:layout_height="fill_parent"--> 
<!--android:id="@+id/mapview"--> 
<!--tools:context="cabse.ui.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"/>