2013-04-28 29 views
6

Lỗi này đã liên tục vĩnh viễn. (Tôi chắc chắn rằng "Google Maps Android API v2" là một trong những bật.)Bản đồ Android: Không thể tải bản đồ. Không thể kết nối với máy chủ Google

Đây là MainActivity.java:

package com.example.maptest; 

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 

public class MainActivity extends FragmentActivity { 

    @Override  
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 

    } 
    @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; 
    }  
} 

Manifest:

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

    <permission 
     android:name="com.example.maptest.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 
    <uses-permission 
     android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 


    <uses-permission android:name="com.example.maptest.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <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-feature 
     android:name="android.hardware.location" 
     android:required="true" /> 
    <uses-feature 
     android:name="android.hardware.location.network" 
     android:required="true" /> 
    <uses-feature android:name="android.hardware.location.gps" /> 
    <uses-feature 
     android:name="android.hardware.wifi" 
     android:required="true" /> 

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <uses-library android:name="com.google.android.maps" /> 

     <activity 
      android:name="com.example.maptest.MainActivity" 
      android:label="@string/app_name" > 
      <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="AIzaSyAoDwhSzOopQ3g8NBe7d0WblR72TkmnVPU" /> 


    </application> 

</manifest> 

activity_main.xml :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 


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

</RelativeLayout> 

Xin vui lòng trợ giúp! Tôi không chắc chắn những gì đã sai ... mặc dù tôi đã kết thúc sau/kết hợp các hướng dẫn khác nhau bởi vì không ai trong số họ làm việc một mình.

+0

1. Are phím ký của bạn và tên gói đăng ký đúng cho rằng khóa API? 2. Bạn đã cho nó bao lâu? Khóa API không phải lúc nào cũng hiệu quả ngay lập tức. –

Trả lời

6

1. Vấn đề đầu tiên tôi thấy là ở đây:

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

loại bỏ dòng này: class = "com.google.android.gms.maps.SupportMapFragment"

và thiết lập android:name như:

android:name="com.google.android.gms.maps.SupportMapFragment" 

2. Hủy bỏ dòng này từ t ông bày tỏ file:

<uses-library android:name="com.google.android.maps" /> 

Đây là Google Maps API V1 phép và không nên sử dụng trong API V2.

Hãy xem bài viết trên blog này và chắc chắn đang làm tất cả mọi thứ một cách chính xác:

Google Maps API V2

3. Vấn đề bạn mô tả thường xuất phát từ một vấn đề trong việc tạo hoặc đăng ký khóa API sử dụng API Console, Nếu bạn tích cực rằng bạn đã thực hiện tất cả các bước một cách chính xác thì tôi khuyên bạn nên xóa thư mục debug.keystore, biên dịch một số dự án trong Eclipse (điều này sẽ dẫn đến khóa SHA1 mới) và đăng ký lại khóa bằng Bàn điều khiển. Hãy xem bài viết trên blog này tôi đã viết và chắc chắn rằng tôi đang làm tất cả các bước đi đúng đắn:

Google Map API V2 Key

+0

Cảm ơn bạn rất nhiều! Đó là hướng dẫn rõ ràng nhất! – Jiexi

+0

bạn chào mừng @hotjasminetea, tôi rất vui vì nó hữu ích cho bạn. –

+0

Xin chào Emil Adz, tôi đã làm theo các bước đó và tạo một ứng dụng mẫu bản đồ thành công. và hoạt động trên hầu hết các thiết bị (tôi đã thử nghiệm trên Galaxy Ace plus, tab Galaxy 7inch và sony xperia Z). nhưng khi tôi cố gắng để kiểm tra tương tự trên HTC Desire hiển thị lỗi của nó như "Không thể tìm thấy lớp 'maps.i.k', tham chiếu từ phương pháp maps.z.ag.a Không thể tải bản đồ. Không thể liên lạc với máy chủ Google" . tôi đã xác minh chéo trong thiết bị mà dịch vụ Google Play được cài đặt. Vì vậy, bạn có thể vui lòng giúp tôi giải quyết vấn đề này không. – Raj

Các vấn đề liên quan