简体   繁体   中英

Fix the Failed to load map. Could not contact Google servers.

I am using the map functionality in my app.Whenever I run map in my app I got error ie

04-19 11:03:50.274: E/Google Maps Android API(23366): Failed to load map. Could not contact Google servers.

I have checked manifest file and code all is correct.And Google play service is also working in my android device. I am running sample code of map same error I have got.But I am not understanding what is exact problem.Please suggest me how to fix that problem. `

Have you adquire your map-key in Google Api Console using the package name of your project and your SH1 of the Keytore? If not, go to console and do it ;) You have to put this key in your Manifest, and the permissions required.

Normally this error happens when:

  • No valid map-key.
  • The key is not for your keystore.
  • You forgot some permision.

===============Mini tutorial=====================

  1. Download and install Google Play Services from SDKManager
  2. Go to Google Api Console
  3. On your left, Create new Project (Give the name you want)
  4. Know in the "services" option is allowed, so go inside the option.
  5. Turn On Google Maps Android API v2
  6. Know in click on "Generate new Android Key" in the page showed
  7. You will need your SHA1 from the Keystore and the name of the project package Ex: 48:+4: ... :46;com.xxxx.xxx.xxx
  8. To know your sha1 you have to open a CMD and do:

     C:\\>cd C:\\Users\\YOURUSER\\.android\\ C:\\Users\\YOURUSER\\.android>"C:\\Program Files\\Java\\jdkXXXX\\bin\\keytool.exe" -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android 

    XXX Means the version you have

  9. Now you got your api key go to your Manifest have to put:

    ... ...

  10. Select the project, right click, go to "File/Import/Android/Existing Android Code into Workspace". In the root directory go to "<-sdk-android folder> /extras/google/google_play_services/libproject/google-play-services_lib" and select the project that appears. Click Finish.

  11. Right click on project go to "Properties/Android"; click on "Add.." button, and choose google play services and click on OK

  12. Add android-support-v4.jar to your project if isn't yet.

  13. THe layout of the map is:

  14. And the activity that contains the map has to extend FragmentActivity (Something like this)

    public class MainActivity extends android.support.v4.app.FragmentActivity {

      @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } ... } 
  15. AAAAND thats all!

您是否使用密钥库和软件包名称为应用程序生成了api密钥?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM