2015-03-11 3 views
0

Я пытаюсь сделать простое приложение с этой картой в студии Android. Но он не отображается в устройстве. Я загрузил heremap api и добавил его в мой проект. Не могли бы вы мне помочь?Здесь карты не отображаются в реальном устройстве

AndroidManifest.xml

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

    <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="com.example.lojika.helloheremaps.MainActivity" 
      android:label="@string/app_name" > 
      <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="XXXXXXXXXXXXXXXXXXXXXX"/> 
     <meta-data android:name="com.here.android.maps.apptoken" 
      android:value="XXXXXXXXXXXXXXXXXXXXXX"/> 

     <service 
      android:name="com.here.android.mpa.service.MapService" 
      android:label="HereMapService" 
      android:process="global.Here.Map.Service.v2" 
      android:exported="true" > 
      <intent-filter> 
       <action android:name="com.here.android.mpa.service.MapService" > 
       </action> 
      </intent-filter> 
     </service> 
    </application> 

</manifest> 

MainActivity.java

package com.example.lojika.helloheremaps; 

import android.app.Activity; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 

import com.here.android.mpa.common.MapActivity; 
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 MainActivity extends Activity { 

    // 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_main); 

     // 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 
        onMapFragmentInitializationCompleted(); 
        // map = mapFragment.getMap(); 
        // Set the map center to the Vancouver region (no animation) 
        //map.setCenter(new GeoCoordinate(15.1447, 120.5957, 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"); 
       } 
      } 
     }); 

    } 
    private void onMapFragmentInitializationCompleted() { 
     // retrieve a reference of the map from the map fragment 
     map = mapFragment.getMap(); 
     // Set the map center coordinate to the Vancouver region (no animation) 
     map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0), 
       Map.Animation.NONE); 
     // Set the map zoom level to the average between min and max (no 
     // animation) 
     map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel())/2); 
    } 


    @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_main, menu); 
     return true; 
    } 

} 

activity_main.xml

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

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="@string/hello_world" 
     tools:context=".MainActivity" /> 

    <!-- 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> 
+0

добавьте '' logcat' и скриншот device' и проверить [это] (HTTP://stackoverflow.com/a/15884512/1761003). – Gattsu

+0

Проверьте свой ключ API. – Piyush

ответ

0

Я думаю, что вы не добавили все необходимые разрешения. Пожалуйста, проверьте ниже изображение. enter image description here

+0

Спасибо за ваш ответ. Я думаю, проблема связана с устройствами. Потому что перед ı попробуйте запустить приложение на устройстве GM Elite, и карта не отображается. Затем ı попробуйте запустить устройство Samsung GT-N5110 и показать карту. Но я не мог найти причину. Вы знаете об этом? –

0

Я знаю, что ответ очень поздний. Но я искал решение той же проблемы. И, возможно, это поможет кому-то.

Служба карты - это служба Android, которая облегчает использование общего дискового кэша среди приложений, использующих SDK ЗДЕСЬ. Эта служба должна быть внедрена и развернута с помощью приложения HERE; в противном случае код ошибки MISSING_SERVICE возвращается через обратный вызов onEngineInitializationCompleted().

Встраивание Map Service, добавьте следующие строки в секции <application> </application> в вашем AndroidManifest.xml file:

<service 
android:name="com.here.android.mpa.service.MapService" 
android:label="HereMapService" 
android:process="global.Here.Map.Service.v2" 
android:exported="true" > 
<intent-filter> 
<action android:name="com.here.android.mpa.service.MapService" > 
</action> 
</intent-filter> 
</service> 
Смежные вопросы