【问题标题】:Map is not Showing in Android device地图未在 Android 设备中显示
【发布时间】:2012-08-07 13:41:46
【问题描述】:

在我的应用程序中,我使用了谷歌地图功能。为此,我使用了自己的密钥库并创建了 MD5 指纹。后来我从谷歌获得了基于 MD5 的我的 xml。

问题:

它在模拟器中工作。但在真实设备中没有显示任何东西。但是网格是可见的。

示例--类

public class First extends MapActivity {
private MapController mc;
private MapView mapView;

private static double current_lat;
private static double current_long;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();
LocationManager mlocManager = (LocationManager)   getSystemService(Context.LOCATION_SERVICE);
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mNetworkListener);

GeoPoint p = new GeoPoint((int)current_lat*(1000000), (int)current_long*(1000000));            
mc.animateTo(p);  

}
private static LocationListener mNetworkListener = new LocationListener() 
{
public void onLocationChanged(Location location) {
makeUseOfNewLocation(location);
}

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}
         public void makeUseOfNewLocation(Location location) {
             current_lat = location.getLatitude();
             current_long = location.getLongitude();
             System.out.println("*** i'm here"+current_lat);

    }

};
@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

Android 清单

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

<application
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name" >

   <activity
     android:name=".First"
     android:label="@string/app_name" >
     <intent-filter>
      <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <uses-library android:name="com.google.android.maps" />
</application>

主要

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

<com.google.android.maps.MapView
 android:id="@+id/mapview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:apiKey="0wINx0c2YuEd3mkyPwidZyeoz_HiyN3jrts-Q" />

</LinearLayout>

Logcat

 08-10 14:27:56.841: W/MapActivity(20815): Recycling dispatcher       android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@405b  9458
 08-10 14:27:56.851: V/MapActivity(20815): Recycling map object.
 08-10 14:27:56.901: I/MapActivity(20815): Handling network change   notification:CONNECTED
 08-10 14:27:56.901: E/MapActivity(20815): Couldn't get connection factory client

谁能弄清楚为什么地图没有显示在设备中。提前谢谢

【问题讨论】:

  • 重新生成 API 密钥并重试
  • 我已经做过很多次了..但是设备中只显示了网格。
  • stackoverflow.com/q/2641197/735675 试试这个。同样的问题。
  • 通过使用自定义调试密钥库,它在 Eclipse 首选项中显示“密钥库被篡改或密码不正确”错误...如何更正此问题?
  • 其实logcat显示一些警告

标签: android google-maps


【解决方案1】:

用此替换您的 mapview xml 代码,然后重试。

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="Your API Key"
/>

还要确保您的设备可以访问互联网。

【讨论】:

    【解决方案2】:

    实际上我发现的问题是 Mapview 仅在应用程序从 android 市场下载时才会显示,因为我们使用的是签名的 api 密钥。

    我认为这就是为什么,它在运行 eclipse 时没有显示。

    【讨论】:

    • 不,当然可以通过android模拟器显示MapView。为此,您必须从以下位置获取 google maps api 密钥:developers.google.com/android/maps-api-signup
    • 对于模拟器,它会显示使用默认密钥库。但是对于设备,我们应该手动创建密钥库,我想是的。
    猜你喜欢
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 2018-03-23
    • 2013-11-09
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 2012-03-09
    相关资源
    最近更新 更多