2015-08-19 46 views
0

大家好,我已經建立了一個移動的地圖api,但設備中的地圖顯示不正確。我會按照這個教程Creating a Simple Application Using the HERE SDK但在logcat中沒有表現出任何的錯誤,我不知道我錯了,請參閱我的代碼這裏的地圖在移動設備上不顯示

這裏映射類:

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 

import com.here.android.mpa.common.GeoCoordinate; 
import com.here.android.mpa.common.OnEngineInitListener; 
import com.here.android.mpa.mapping.Map; 
import com.here.android.mpa.mapping.MapFragment; 

public class hereMap extends AppCompatActivity { 

    // map embedded in the map fragment 
    private Map map = null; 

    // map fragment embedded in this activity 
    private MapFragment mapFragment = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_here_map); 

     // Search for the map fragment to finish setup by calling init(). 
     mapFragment = (MapFragment)getFragmentManager().findFragmentById(
       R.id.mapfragment); 
     mapFragment.init(new OnEngineInitListener() { 
      @Override 
      public void onEngineInitializationCompleted(
        OnEngineInitListener.Error error) 
      { 
       if (error == OnEngineInitListener.Error.NONE) { 
        // retrieve a reference of the map from the map fragment 
        map = mapFragment.getMap(); 
        // Set the map center to the Vancouver region (no animation) 
        map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0), 
          Map.Animation.NONE); 
        // Set the zoom level to the average between min and max 
        map.setZoomLevel(
          (map.getMaxZoomLevel() + map.getMinZoomLevel())/2); 
       } else { 
        System.out.println("ERROR: Cannot initialize Map Fragment"+error.toString()); 
       } 
      } 
     }); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_here_map, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

這裏地圖活動:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <!-- Map Fragment embedded with the map object --> 
    <fragment 
     class="com.here.android.mpa.mapping.MapFragment" 
     android:id="@+id/mapfragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</LinearLayout> 

清單文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="mpat.bkklife" > 

    <!-- To auto-complete the email text field in the login form with the user's emails --> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="android.permission.READ_PROFILE" /> 
    <uses-permission android:name="android.permission.READ_CONTACTS" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <activity 
      android:name=".LoginActivity" 
      android:label="@string/app_name" 
      android:windowSoftInputMode="adjustResize|stateVisible" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <meta-data android:name="com.here.android.maps.appid" android:value="My App ID:************"/> 
     <meta-data android:name="com.here.android.maps.apptoken" android:value="My App Token:***********"/> 
     <meta-data android:name="com.here.android.maps.license.key" android:value="My License Key:***********"/> 

     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main" > 
     </activity> 
     <activity 
      android:name=".hereMap" 
      android:label="@string/title_activity_here_map" > 
     </activity> 
    </application> 

</manifest> 

UPDATE 當我的應用程序初始化映射時,我在日誌貓中出現錯誤,它說「錯誤:無法初始化Map碎片MISSING_LIBRARY」。但是我已經包含了HERE SDK和armeabi-v7a。

SpecDevice:Galaxsy S4的Android 5.0.1棒棒糖 Screen capture

,這是我在項目的lib:

Lib Folder

什麼,我錯了我的代碼?感謝每一位。

+0

LogCat中是否有任何錯誤? –

+2

你有沒有用正確的值代替那些「我的APP ID」,令牌和許可證密鑰,有時我們按照教程這是一些普遍被忽視的東西。你可以檢查 – Shiv

+0

我會檢查所有這件事情它是正確的我的應用程序的細節在這裏我帳戶的地圖,但我得到了在日誌貓日誌消息「錯誤:無法初始化地圖碎片」在mapFragment.init部分。 –

回答

1

嘗試改變這一行:

System.out.println("ERROR: Cannot initialize Map Fragment"); 

這樣:

System.out.println("ERROR: Cannot initialize Map Fragment: " + error.toString()); 

然後檢查日誌,看看你是什麼接收OnEngineInitListener.Error。這將幫助您找到問題的根源。

正如Shiv在評論中提到的那樣,根據您發佈的AndroidManifest,它看起來像是可能缺少appId appCode和/或許可證密鑰的罪魁禍首。

作爲一個側面說明,而不是的System.out.println,你應該使用android.util.Log

+0

好的,我更新包括error.toString()在日誌中,我嘗試運行看log.It說「錯誤:無法初始化地圖碎片MISSING_LIBRARY」但我SDK和armeabi-V7A這裏補充到應用程序的庫。 ps。我已經從這裏地圖賬號 –

+0

添加應用標識appCode和許可證密鑰當你說「已經添加到應用程序庫」你的意思是你在庫/文件夾的地方,你的應用程序?路徑應該是: /庫/ armeabi-V7A/ AndrewJC

0

另外,你在清單文件中的以下行填寫:

<meta-data android:name="com.here.android.maps.appid" android:value="My App ID"/> 
    <meta-data android:name="com.here.android.maps.apptoken" android:value="My App Token"/> 
    <meta-data android:name="com.here.android.maps.license.key" android:value="My License Key"/> 

請插入appid,令牌和評估密鑰,您在註冊應用程序時獲得的。

另外,你是否從SDK軟件包複製本機庫?

的結構應該是: 「項目根目錄」 \庫\ armeabi-V7A *。所以

+0

好的,我更新包括日誌error.toString()和我嘗試運行看log.It說,「ERROR :無法初始化Map Fragment MISSING_LIBRARY「,但是我將HERE SDK和armeabi-v7a添加到應用程序的庫中。 ps。我已經在這裏添加appId appCode和許可證密鑰地圖帳戶 –

+0

您可以讓我們知道哪些文件在libs文件夾中? –

0

它看起來像SDK包只包括armeabi本地庫,所以當你嘗試與設備上運行一個不同的CPU架構(見https://developer.android.com/ndk/guides/abis.html),它找不到合適的二進制文件。

如果您發現解決方法,我會很好奇,因爲這會阻止我的應用在任何使用非armeabi CPU的設備上工作。

0

請檢查您申請

重要補充,其命名空間:你必須使用相同的包名,你已註冊developer.here.com。如果不這樣做,會導致出現在應用程序中的空白地圖。

一段時間,我們建立時間短的應用所以我們錯過了幾步它是可能的。

如果我們正在處理多個應用程序,它會發生:)

相關問題