大家好,我已经为移动设备构建了一个这里 map API,但设备中出现问题, map 未显示。我将按照本教程Creating a Simple Application Using the HERE SDK进行操作但在 Logcat 中没有显示任何错误,我不知道我错了什么,请查看我的代码
此处 map 类:
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);
}
}
这里的 map Activity :
<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>
list 文件:
<?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>
更新 当我的应用程序初始化 map 时,我在 log cat 中收到错误,显示“错误:无法初始化 map fragment MISSING_LIBRARY”。但我已经包含了 HERE SDK 和armeabi-v7a。
规范设备:Galaxsy S4 android 5.0.1 Lollipop
这是我在项目中的库:
我的代码有什么问题吗?谢谢大家。
最佳答案
尝试更改此行:
System.out.println("ERROR: Cannot initialize Map Fragment");
对此:
System.out.println("ERROR: Cannot initialize Map Fragment: " + error.toString());
然后检查日志以查看您收到的 OnEngineInitListener.Error
内容。这将帮助您找到问题的根本原因。
正如 Shiv 在评论中提到的,根据您发布的 AndroidManifest,罪魁祸首可能是缺少 appId、appCode 和/或许可证 key 。
顺便说一句,您应该真正使用android.util.Log,而不是System.out.println。
关于java - 这里的 map 在移动设备中不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32091311/