Android Studio Emulator:身份验证失败.尝试联系服务器时超时



我正在尝试学习Android开发,第一次这样做是为了动手开发我的想法。我想在模拟器上加载带有当前位置的谷歌地图。

已参考 SE 问题:无法加载地图。联系 Google 服务器时出错。这可能是身份验证问题

最初,我遇到了"除非我在安卓工作室中更新谷歌播放服务,否则不会运行"的问题

更改后问题已解决:

compile 'com.google.android.gms:play-services:9.0+

我还通过从代码文件中给出的链接生成API_KEY来更正API_KEY。现在我没有收到该错误,但仍然无法在模拟器上加载地图。这些似乎是连接问题,我也在清单文件中添加了权限。但问题仍然存在。请指导我并提供您的宝贵建议。

google_maps_api.xml

<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=6C:42:DD:0A:5D:D3:E4:5E:79:C9:04:81:3A:7A:70:17:25:37:97:96%3Bcom.example.kapilj3.meetmeapp
You can also add your credentials to an existing key, using this line:
6C:42:DD:0A:5D:D3:E4:5E:79:C9:04:81:3A:7A:70:17:25:37:97:96;com.example.kapilj3.meetmeapp
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIza_MY_ACTUAL_KEY</string>
</resources>

安卓清单.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />

将此代码添加到您的应用程序

最新更新