简体   繁体   English

这里的地图不显示在真实设备中

[英]Here maps doesn't show in real device

I try to make a simple app with here map in Android studio. 我尝试使用Android Studio中的此处地图制作一个简单的应用程序。 But it doesn't display in device. 但它不会显示在设备中。 I downloaded heremap api and add it's jar to my project. 我下载了heremap api并将其添加到我的项目中。 Can you help me please? 你能帮我吗?

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>

I think you did not added all permission required, Please check below image 我认为您没有添加所需的所有权限,请检查下图 在此处输入图片说明

I know that the answer is very late. 我知道答案很晚。 But I was looking for a solution to the same problem. 但是我一直在寻找解决同一问题的方法。 And maybe it will help someone. 也许它将帮助某人。

Map Service is an Android service that facilitates the use of a shared disk cache among applications that use the HERE SDK. Map Service是一项Android服务,可促进使用HERE SDK的应用程序之间共享磁盘缓存的使用。 This service must be embedded and deployed with your HERE-enabled application; 此服务必须与已启用HERE的应用程序一起嵌入和部署; otherwise, the MISSING_SERVICE error code is returned via the onEngineInitializationCompleted() callback. 否则,将通过onEngineInitializationCompleted()回调返回MISSING_SERVICE错误代码。

To embed Map Service, add the following lines inside the <application> </application> section in your AndroidManifest.xml file : 要嵌入地图服务,请在AndroidManifest.xml file<application> </application>部分内添加以下行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM