我正在为我的应用程序使用Android Google Map API-2。单击地图视图时,它仅显示带缩放按钮的屏幕。
我的AndroidManifest.xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.burusoth.advertise"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.burusoth.advertise.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.burusoth.advertise.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.CALL_PHONE" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.burusoth.advertise.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>
<activity
android:name="com.burusoth.advertise.View_Advertisements"
android:label="@string/title_activity_view__advertisements" >
</activity>
<activity
android:name="com.burusoth.advertise.Gadget_view"
android:label="@string/title_activity_gadget_view"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.burusoth.advertise.Activity_post_advertisements"
android:label="@string/title_activity_activity_post_advertisements" >
</activity>
<activity
android:name="com.burusoth.advertise.Post_Advertisement"
android:label="@string/title_activity_post__advertisement" >
</activity>
<activity
android:name="com.burusoth.advertise.Popup"
android:label="@string/title_activity_popup" >
</activity>
<activity
android:name="com.burusoth.advertise.Google_Map"
android:label="@string/title_activity_google__map" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAKCvpyR3v4YStDJDoibNgoblkdch0F254" />
</application>
my activity xml file
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Google_Map" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
我的Activity .java用于调用map的Activity文件 公共类Google_Map扩展了活动{
private GoogleMap googleMap=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google__map);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_google__map, menu);
return true;
}
private void initilizeMap() {
if (googleMap == null) {
googleMap =((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
答案 0 :(得分:1)
在此,我想分享一个在Google Map API v2下运行的示例。 您可以执行这些步骤,也可以从下面的链接下载完整的示例。
这是一个有效的例子。请在真实设备中测试。
Google Maps API v2 using Android
如果您有任何疑问,请提供您的评论。
答案 1 :(得分:0)
您需要将API_KEY放入Android清单中 从获得 : Google Map API_KEY