gpt4 book ai didi

android - Google Maps Android API v2 显示空白 map

转载 作者:行者123 更新时间:2023-11-29 20:50:45 27 4
gpt4 key购买 nike

我正在尝试实现一个简单的 map ,我已经在我的 list 文件中添加了所有用户权限并启用了 Google API V2。它仍然只显示一张空白 map 。

list_doctor.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" >



<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

list_doctor.java

public class listDoctor extends Activity implements OnMapReadyCallback{
private MapFragment fragment;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listdoctor);
try {
// Loading map
initilizeMap();

} catch (Exception e) {
e.printStackTrace();
}

}

/**
* function to load map. If map is not created it will create it for you
*/
private void initilizeMap() {
if (fragment == null) {
fragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
fragment.getMapAsync(this);
// check if map is created successfully or not
if (fragment == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}

@Override
protected void onResume() {
super.onResume();
initilizeMap();
}

@Override
public void onMapReady(GoogleMap map) {
LatLng sydney = new LatLng(-33.867, 151.206);

map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));

map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}

}

list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.winthrop"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.winthrop.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="com.winthrop.permission.MAPS_RECEIVE" />

<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />

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

<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- 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">
<activity
android:name="com.winthrop.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
</activity>

<!-- Goolge API Key -->
<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="692634518367-dgd8tgncr13tcvhpj5uuj9bmm66d52pq" />

</application>

</manifest>

logcat 错误

03-23 11:06:31.054: E/Google Maps Android API(15456): Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.

最佳答案

您错过了与 API_KEY 生成和使用相关的内容。请重新检查您是否为您的包名称 com.winthrop 正确生成了 API_KEY。您可以引用以下步骤:here

关于android - Google Maps Android API v2 显示空白 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29204171/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com