地图没有出现在我的应用程序中,我无法弄清楚我的代码有什么问题我已经尽力解决这个问题,希望你能帮我解决这个问题,这里是主要的布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:background="#fffffbec"
android:id="@+id/heady">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="127dp"
android:layout_gravity="top"
android:layout_weight="0.86"
android:weightSum="1"
android:id="@+id/bodylay"
android:gravity="bottom">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="@+id/acquiring_signal_layout"
android:background="#fff8edff"
android:gravity="center_vertical">
<ProgressBar
android:id="@+id/ProgressBar01"
style="@color/green"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/acquiring_signal_label"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="5dp"
android:text="@string/acquiring_signal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ff12bec1" />
</LinearLayout>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MapView"
android:layout_width="match_parent"
android:layout_height="274dp"
android:apiKey="0oR0G95fEqsQy8FGrgFXeZ4U3NnHNmRZUbPh_8A"
android:clickable="true"
android:layout_weight="0.81" />
</LinearLayout>
<Button
android:id="@+id/SendButton"
android:layout_width="238dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/send_button"
android:visibility="visible"
android:layout_gravity="center"
android:background="#ff12bec1"
android:layout_weight="0.11"
android:textColor="#fffefff3" />
</LinearLayout>
这是主要的节日:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"
package="com.mylocation.hanan.mylocation" >
<uses-sdk android:targetSdkVersion="13" android:minSdkVersion="9"></uses-sdk>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.NoActionBar" >
<!--@style/AppTheme-->
<uses-library android:required="true" android:name="com.google.android.maps"></uses-library>
<activity
android:name="com.mylocation.hanan.mylocation.Sharelocation"
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.mylocation.hanan.mylocation.Preferences"
android:label="@string/preferences_activity">
<intent-filter>
<action android:name="com.mylocation.hanan.mylocation.action.Preferences" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:1)
要点:
1。您使用的旧版Google地图已不再受支持。
2。您可能使用了错误的API密钥。
3。您尚未在清单文件中添加适当的权限。
4. 确保您已将Google Play服务库包含在项目中。
可能的解决方案,
A. 在xml中添加支持地图片段
<fragment xmlns: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"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
B. 使用活动中的支持地图片段并实现onMapReadyCallback
public class MapPane extends Activity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_activity);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
}
}
来源:
C。在清单文件上添加适当的权限
<!-- Creating Permission to receive Google Maps -->
<permission
android:name="com.example.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<!-- Permission to receive Google Maps -->
<uses-permission android:name="com.example.app.permission.MAPS_RECEIVE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_GOOGLE_MAP_APIKEY" />
D。要获取Google Maps API密钥,请按照此处的说明进行操作