android - 谷歌地图只显示灰色瓷砖而不是 map

标签 android google-maps

过去 4 天我一直在使用 Google Maps API v2,但显示 Google map 失败但只显示灰色图 block 。在模拟器和真实设备(作为模拟器连接到 PC)上运行应用程序时,Eclipse 没有显示任何错误。我提到的 API key (代替我的 api key )是我通过显示调试证书指纹获得。任何人请。帮助!提前致谢。

list 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.VertexVerveInc.GPSLocator"
android:versionCode="1"
android:versionName="1.0" >
<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-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
     android:allowBackup="true"
    android:icon="@drawable/icon" 
    android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps"/>
    <activity
        android:name="GPSLocatorActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
       </activity>
      </application>

    </manifest>

ma​​in.xml 文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical"
 android:layout_width="fill_parent"  
 android:layout_height="fill_parent">
<com.google.android.maps.MapView 
android:id="@+id/mapView"  
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:enabled="true" 
android:clickable="true" 
android:apiKey="my api key"
/>
</LinearLayout>

GPSLocatorActivity.java 文件

package com.VertexVerveInc.GPSLocator;


import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.GeoPoint;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;

import android.location.Geocoder;
import android.location.Address;

import com.google.android.maps.Overlay;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.util.List;
import java.util.Locale;
import java.io.IOException;

import android.os.Bundle;
import android.widget.Toast;

public class GPSLocatorActivity extends MapActivity {

private MapView mapView;
private MapController mapController;

private LocationManager locationManager;
private LocationListener locationListener;

@SuppressWarnings( "deprecation" )

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);    

    locationListener = new GPSLocationListener();

    locationManager.requestLocationUpdates(
        LocationManager.GPS_PROVIDER, 
        0, 
        0, 
        locationListener);

    mapView = (MapView) findViewById(R.id.mapView);

    // enable Street view by default
    mapView.setStreetView(true);

    // enable to show Satellite view
     mapView.setSatellite(true);

    // enable to show Traffic on map
     mapView.setTraffic(true);
    mapView.setBuiltInZoomControls(true);

    mapController = mapView.getController();
    mapController.setZoom(16); 
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

private class GPSLocationListener implements LocationListener 
{
    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
            GeoPoint point = new GeoPoint(
                    (int) (location.getLatitude() * 1E6), 
                    (int) (location.getLongitude() * 1E6));

            /* Toast.makeText(getBaseContext(), 
                    "Latitude: " + location.getLatitude() + 
                    " Longitude: " + location.getLongitude(), 
                    Toast.LENGTH_SHORT).show();*/

            mapController.animateTo(point);
            mapController.setZoom(16);

            // add marker
            MapOverlay mapOverlay = new MapOverlay();
            mapOverlay.setPointToDraw(point);
            List<Overlay> listOfOverlays = mapView.getOverlays();
            listOfOverlays.clear();
            listOfOverlays.add(mapOverlay);

            String address = ConvertPointToLocation(point);
            Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

            mapView.invalidate();
        }
    }

    public String ConvertPointToLocation(GeoPoint point) {   
        String address = "";
        Geocoder geoCoder = new Geocoder(
                getBaseContext(), Locale.getDefault());
        try {
            List<Address> addresses = geoCoder.getFromLocation(
                point.getLatitudeE6()  / 1E6, 
                point.getLongitudeE6() / 1E6, 1);

            if (addresses.size() > 0) {
           for (int index = 0; index <                                   addresses.get(0).getMaxAddressLineIndex(); index++)
                    address += addresses.get(0).getAddressLine(index) + " ";
            }
        }
        catch (IOException e) {                
            e.printStackTrace();
        }   

        return address;
    } 

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}

class MapOverlay extends Overlay
{
    private GeoPoint pointToDraw;

    public void setPointToDraw(GeoPoint point) {
        pointToDraw = point;
    }

    public GeoPoint getPointToDraw() {
        return pointToDraw;
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
        super.draw(canvas, mapView, shadow);                   

        // convert point to pixels
        Point screenPts = new Point();
        mapView.getProjection().toPixels(pointToDraw, screenPts);

        // add marker
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.red);
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null); // 24 is the      height of image        
        return true;
    }
} 

最佳答案

如果你使用签名的apk,debug key export means, map 在真实设备上看起来是空白的。您正在使用未签名的 apk,即调试 key 。如果导出 apk,请使用发布 key 。

https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key

已提供释放证书指纹。

list 中缺少一些权限。请添加。

    <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
    <permission
    android:name="com.VertexVerveInc.GPSLocator.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.VertexVerveInc.GPSLocator.permission.MAPS_RECEIVE" />

在布局中,您正在使用 map v1,切换到 map v2。

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

http://www.vogella.com/articles/AndroidGoogleMaps/article.html

关于android - 谷歌地图只显示灰色瓷砖而不是 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16955701/

相关文章:

android - MapBox 设置样式回调有时不起作用,mapbox map 变灰

android - 摩托罗拉 Defy 上的 ImageView 是黑色的

java - 抽屉 fragment 内的 Google map ,未找到 ID XXXXXXX 的 View

android - 谷歌地图从异步任务加载多个标记

ios - 适用于 iOS 的 Google map ,swift - 如何在标记之间显示整条多段线?

android - ZTE Android 版本 4.0.4 上的着色器损坏

android - 让 BroadcastReceiver 在后台作为服务运行 + 开机后自动启动

php - 如何将动态谷歌地图添加到我的网站?

ios - 在 iOS 中创建不适合整个屏幕的 Google map

android - 设置 TextView 椭圆大小并在末尾添加更多 View