首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >无法在Android Eclipse中加载Google地图

无法在Android Eclipse中加载Google地图
EN

Stack Overflow用户
提问于 2015-07-02 18:44:06
回答 2查看 233关注 0票数 0

我在我的应用程序中使用Google地图,但在运行此应用程序时出现以下错误

授权失败。

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开发者控制台(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密钥: 07-02 12:44:45.563: E/Google Maps Android API(2447):接口密钥: AIzaSyCwWioLbwEVhUGFf6BN-prF984pFcfKCOw 07-02 12:44:45.563: E/Google地图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

致以问候,普拉纳夫

EN

回答 2

Stack Overflow用户

发布于 2015-07-02 18:49:59

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

我想你没有拿到钥匙。您必须为调试模式https://developer.android.com/tools/publishing/app-signing.html#debugmode生成证书

票数 0
EN

Stack Overflow用户

发布于 2015-07-02 19:47:30

首先在您的https://console.developers.google.com/上配置SHA1密钥

使用以下方法生成sha1 (每台计算机都有自己的sha1密钥,因此如果您更换pc,则需要重新配置sha1密钥):

代码语言:javascript
代码运行次数:0
运行
复制
 C:\Users\admin\.android>keytool -list -v -keystore debug.keystore

复制它并放入您的google应用程序帐户,如sha1key;packagename,然后从google开发人员控制台生成api-key。复制此api-key。

检查是否获取了以下权限:

代码语言:javascript
代码运行次数:0
运行
复制
<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 :

代码语言:javascript
代码运行次数:0
运行
复制
<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文件:

代码语言:javascript
代码运行次数:0
运行
复制
  <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的复制粘贴:

代码语言:javascript
代码运行次数:0
运行
复制
 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;
      }
    }
 }

希望它能很好地为你工作,也能对其他人有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31182396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档