Android地图只显示网格,不显示任何地图视图

Android地图只显示网格,不显示任何地图视图,android,google-maps,geolocation,Android,Google Maps,Geolocation,我正在开发一个小型android应用程序,我想在其中向用户显示地图上的当前位置。出于这个原因,我正在使用谷歌地图API。我遵循获取map api密钥所需的所有设置。我在该位置获得默认密钥存储。我从诸如SHA1键和MD5键之类的键中获取所有必需的值。然后在GoogleAPI控制台上,我使用SHA1+package_名称获取API键。我还启用了谷歌地图API v2服务 现在在我的项目方面,我做了以下事情 // in main.xml <LinearLayout xmlns:android="h

我正在开发一个小型android应用程序,我想在其中向用户显示地图上的当前位置。出于这个原因,我正在使用谷歌地图API。我遵循获取map api密钥所需的所有设置。我在该位置获得默认密钥存储。我从诸如SHA1键和MD5键之类的键中获取所有必需的值。然后在GoogleAPI控制台上,我使用SHA1+package_名称获取API键。我还启用了谷歌地图API v2服务

现在在我的项目方面,我做了以下事情

// in main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
    android:id="@+id/myLocationText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
        android:text="@string/hello_world"
    tools:context=".WhereAmI" />

    <com.google.android.maps.MapView
        android:id="@+id/myMapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="AIzaSyD6EHgxObm01ooCF9DsMzOppJbNp8O2_j4"
    />

</LinearLayout>


// In manifest file 

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.INTERNET"/>

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

//mapactivity..........
public class mapview extends MapActivity {

    private MapController mapController;

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

    private final LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
        updateWithNewLocation(location);

        }
        public void onProviderDisabled(String provider) 
        {

        }
        public void onProviderEnabled(String provider) 
        {

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

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

    MapView myMapView = (MapView)findViewById(R.id.myMapView);
    mapController = myMapView.getController();
    myMapView.setSatellite(true);
    myMapView.setBuiltInZoomControls(true);
    mapController.setZoom(17);

    //LocationManager locationManager;
    String svcName = Context.LOCATION_SERVICE;
    locationManager = (LocationManager)getSystemService(svcName);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);
    String provider = locationManager.getBestProvider(criteria, true);

    //dis(provider);
    //Location l = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);
    Location l = locationManager.getLastKnownLocation(provider);

    updateWithNewLocation(l);

    locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);

    }


    private void updateWithNewLocation(Location location) 
    {
        TextView myLocationText;
        myLocationText = (TextView)findViewById(R.id.myLocationText);
        String latLongString = "No location found";
        String addressString = " No address found";
        //Toast.makeText(this, "inside update location", Toast.LENGTH_SHORT).show();

        if (location != null) 
        {
            double lat = location.getLatitude();
            double lng = location.getLongitude();
            latLongString = "Lat:" + lat + "\nLong:" + lng;
            Geocoder gc = new Geocoder(this, Locale.getDefault());
            Double geoLat = location.getLatitude()*1E6;
            Double geoLng = location.getLongitude()*1E6;
            GeoPoint point = new GeoPoint(geoLat.intValue(),geoLng.intValue());
            mapController.animateTo(point);

            try {
                List<Address> addresses = gc.getFromLocation(lat, lng, 1);
                StringBuilder sb = new StringBuilder();
                if (addresses.size() > 0) {
                Address address = addresses.get(0);
                for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
                sb.append(address.getAddressLine(i)).append("\n");
                sb.append(address.getLocality()).append("\n");
                sb.append(address.getPostalCode()).append("\n");
                sb.append(address.getCountryName());
                }
                addressString = sb.toString();
                } catch (IOException e) {}

                myLocationText.setText("Your Current Position is:\n" +
                latLongString + "\n\n" + addressString);

        }

    }

    @Override
    public void onDestroy() 
    {
    super.onDestroy();
    locationManager.removeUpdates(locationListener);
    }

}
//在main.xml中
//在清单文件中
//地图活动。。。。。。。。。。
公共类mapview扩展了MapActivity{
专用地图控制器;
@凌驾
受保护的布尔值isRouteDisplayed(){
返回false;
}
私有最终位置Listener LocationListener=新位置Listener(){
已更改位置上的公共无效(位置){
updateWithNewLocation(位置);
}
公共无效onProviderDisabled(字符串提供程序)
{
}
公共无效onProviderEnabled(字符串提供程序)
{
}
public void onStatusChanged(字符串提供程序,int状态,
捆绑(附加)
{
}
};
地点经理地点经理;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView myMapView=(MapView)findViewById(R.id.myMapView);
mapController=myMapView.getController();
myMapView.setSatellite(真);
myMapView.SetBuilTinZoomControl(真);
mapController.setZoom(17);
//地点经理地点经理;
字符串svcName=Context.LOCATION\u服务;
locationManager=(locationManager)getSystemService(svcName);
标准=新标准();
标准.设定准确度(标准.准确度/精细度);
标准。设置功率要求(标准。功率低);
标准。setAltitudeRequired(false);
标准。需要设置(假);
标准。设置所需速度(假);
条件.setCostAllowed(true);
字符串提供程序=locationManager.getBestProvider(条件为true);
//dis(供应商);
//Location l=locationManager.getLastKnownLocation(locationManager.NETWORK\u提供程序);
Location l=locationManager.getLastKnownLocation(提供者);
更新新位置(l);
locationManager.RequestLocationUpdate(提供者,2000,10,locationListener);
}
私有void updateWithNewLocation(位置)
{
text查看我的位置text;
myLocationText=(TextView)findViewById(R.id.myLocationText);
String latlonString=“未找到位置”;
String addressString=“找不到地址”;
//Toast.makeText(这是“内部更新位置”,Toast.LENGTH_SHORT).show();
如果(位置!=null)
{
双纬度=location.getLatitude();
double lng=location.getLongitude();
LATLONSTRING=“Lat:+Lat+”\nLong:+lng;
Geocoder gc=新的Geocoder(这个,Locale.getDefault());
双geoLat=location.getLatitude()*1E6;
Double geoling=location.getLongitude()*1E6;
地质点=新的地质点(geoLat.intValue(),geoling.intValue());
mapController.animateTo(点);
试一试{
列表地址=gc.getFromLocation(lat,lng,1);
StringBuilder sb=新的StringBuilder();
如果(地址.size()>0){
地址=地址。获取(0);
对于(int i=0;i
现在我的问题是,当我在模拟器或设备上运行这个应用程序时,它会给我正确的坐标和位置,但它不会显示地图视图。它仅显示灰色栅格视图。我知道关于同一个问题有很多重复的问题,但我仍然无法摆脱这个问题。我还创建了自定义调试键,并使用该键的SHA1值,但不改变输出。有没有解决这个问题的办法。。。 需要帮助。。。
谢谢你

如果无法下载地图,可能存在以下两个问题之一:

1) 您使用的API版本已弃用。 2) 您没有快速的internet连接

您显示的代码使用API v1,并且您使用API v2的键。我不确定这是否有效,但使用键为v2的API v2肯定有效。看这里。 也可以使用片段而不是地图视图


还可以在真实设备上试用,因为emulator存在一些问题,如图所示

互联网速度是否足以下载地图贴片?我等待了很长时间,但它无法工作…:(它给我错误无法获取连接工厂客户端你在真实设备上尝试了吗?看起来这是模拟器的一个错误。看看这里是的,我在真实设备上也尝试了,但给出了相同的输出。在api控制台上,我正在启用服务google map api v2。以及在少数位置读取使用MD5键和位置SHA1。如果使用md5值,则它不接受该值。仅接受SHA1值。API键中有问题吗?Hi rajat试图遵循您的给定解决方案。但当我尝试将google play lib添加到我的项目中时,它在我的android项目上给出了红色标记(不交叉)。当我尝试运行我的项目时,它会给我错误,即您的项目已被删除