HERE SDK:无法初始化Map Fragment:OPERATION_NOT_ALLOWED

时间:2016-04-02 07:02:13

标签: java android-studio here-api

我收到此错误并且地图未显示(只是一个空白屏幕),即使我添加了我的应用ID +应用代码+许可密钥, 我使用的是Mobile SDK premium(试用版),我遵循了这个example

这是我的代码

Android Manifest.xml

<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.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".BasicMapActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <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="{app id}"/>
    <meta-data android:name="com.here.android.maps.apptoken"
               android:value="{app code}"/>
    <meta-data android:name="com.here.android.maps.license.key"
               android:value="{License key}"/>

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

BasicMapActivity.java

public class BasicMapActivity extends Activity {
// map embedded in the map fragment
    private Map map = null;
    // map fragment embedded in this activity
    private MapFragment mapFragment = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basic_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());
                }
            }
        });
    }
}

activity_basic_map.xml

<?xml version="1.0" encoding="utf-8"?>
<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:text="hello_world"
        tools:context=".BasicMapActivity" />

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

1 个答案:

答案 0 :(得分:0)

在清单文件中,尝试将服务标记放在应用程序标记之外。 我希望它能解决你的问题