我正在尝试在Android应用程序中使用Google Map但我在运行应用程序时无法看到Map。我唯一能看到的是带有zoomin的缩略图 - zoomoout符号。我尝试了很多stackoverflow解决方案,但无法通过它。请帮我躲开这个。非常感谢你。
我按照此链接获取Google地图密钥 -
我的Apps Manifest.xml如下 -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.surajkumar.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@drawable/pin_location"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.surajkumar.myapp.MainActivity"
android:label="@string/app_tag" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/gmap_apiv2_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
布局文件如下 -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:background="@color/honeydew"
>
<TextView
android:id="@+id/yourlocationtxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Refresh to get your location"/>
<LinearLayout
android:id="@+id/mapsection"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:orientation="vertical"
android:padding="4dp">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
<Button
android:id="@+id/sendsms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sendlocationbtntxt"
android:background="@drawable/button_style"/>
</LinearLayout>
活动代码如下 -
package com.surajkumar.myapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends Activity {
private GoogleMap peoplesLocMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
peoplesLocMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:1)
你应该改变这个
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
到
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
还添加<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
在你的清单
答案 1 :(得分:0)
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
到
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
并在清单
中添加您自己的权限<permission
android:name="yourPackagename.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="yourPackagename.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
就是这样
答案 2 :(得分:0)
确保您的清单中包含以下内容:
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.surajkumar.myapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="com.surajkumar.myapp.permission.MAPS_RECEIVE" />
这应该在应用程序结束标记之前:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
更改此
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
到
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
并从您的活动中加载地图:
GoogleMap gMap;
在onCreate中:
FragmentManager fragmentManager = getFragmentManager();
MapFragment mapFragment = (MapFragment) fragmentManager.findFragmentById(R.id.map);
gMap = mapFragment.getMap();
尝试再次检查你提到的link,看看你是否错过了什么,并确保你正确生成了密钥,因为你所描述的空白视图,但放大/缩小标志显示的是很多时候关键相关问题
祝你好运......