无法在Android Eclipse中加载Google地图

时间:2015-07-02 10:44:06

标签: android api

我在我的应用中使用谷歌地图,但在运行此

时收到以下错误

授权失败。

07-02 12:44:45.559:E / Google Maps Android API(2447):授权失败。有关如何正确设置地图的信息,请参阅https://developers.google.com/maps/documentation/android/start。 07-02 12:44:45.563:E / Google Maps Android API(2447):在Google Developer Console中(https://console.developers.google.com) 07-02 12:44:45.563:E / Google Maps Android API(2447):确保已启用“Google Maps Android API v2”。 07-02 12:44:45.563:E / Google Maps Android API(2447):确保存在以下Android Key: 07-02 12:44:45.563:E / Google Maps Android API(2447):API密钥:AIzaSyCwWioLbwEVhUGFf6BN-prF984pFcfKCOw 07-02 12:44:45.563:E / Google Maps Android API(2447):Android应用程序(;):95:31:6E:43:EB:62:90:0D:4E:48:0D:94:FC :27:22:88:79:1A:06:3C; com.scanchex.ui

此致 Pranav

2 个答案:

答案 0 :(得分:0)

要整合谷歌地图,请关注https://developers.google.com/maps/documentation/android/start

我认为你没有得到任何钥匙。您必须为调试模式https://developer.android.com/tools/publishing/app-signing.html#debugmode

生成证书

答案 1 :(得分:0)

首先在https://console.developers.google.com/

上配置SHA1

使用以下方法生成sha1(每台计算机都有自己的sha1键,所以如果你改变你的电脑,那么你重新配置sha1键):

 C:\Users\admin\.android>keytool -list -v -keystore debug.keystore

将其复制并放入您的google应用程序帐户,例如sha1key; packagename并从google开发者控制台生成api-key。复制这个api-key。

检查是否接受以下许可:

<permission
   android:name="com.javapapers.currentlocationinmap.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.javapapers.currentlocationinmap.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

设置元数据和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="api-key from the google developer console" />

复制并粘贴以下activity_map.xml文件:

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/rl_raw_header">

    <fragment
        android:id="@+id/googleMap"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/latlongLocation" />

    <TextView
        android:id="@+id/latlongLocation"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#ff058fff"
        android:gravity="bottom"
        android:paddingBottom="5dp"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:paddingTop="5dp"
        android:textColor="#ffffffff" />
</RelativeLayout>

按照Map_Activity复制粘贴:

 public class Map_Activity extends FragmentActivity implements  LocationListener {

   GoogleMap googleMap;
   ImageView img_chat_back;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //show error dialog if GoolglePlayServices not available
    if (!isGooglePlayServicesAvailable()) {
        finish();
    }
    setContentView(R.layout.activity_map);


    SupportMapFragment supportMapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
    googleMap = supportMapFragment.getMap();
    googleMap.setMyLocationEnabled(true);
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    String bestProvider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(bestProvider);
    if (location != null) {
        onLocationChanged(location);
    }

}

@Override
public void onLocationChanged(Location location) {
    TextView locationTv = (TextView) findViewById(R.id.latlongLocation);
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
    LatLng latLng = new LatLng(latitude, longitude);
    googleMap.addMarker(new MarkerOptions().position(latLng));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
    locationTv.setText("Latitude:" + latitude + ", Longitude:" + longitude);
}

private boolean isGooglePlayServicesAvailable() {
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (ConnectionResult.SUCCESS == status) {
        return true;
    } else {
        GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
        return false;
      }
    }
 }

希望它能为你工作,也有助于他人。