2011-05-07 97 views
0

亲爱的,我想显示谷歌地图上我的应用程序正在模拟器上运行...但哪个api键我没有工作,并在模拟器只有瓷砖显示不地图显示什么要在我的模拟器中显示地图,我在android和java中都是新的,所以请简要地介绍一下exlinse中的thanklin ...我已经阅读了“获取MD5指纹”,但没有站在如何实现它,所以逐步解释.. .PLS PSL请.. 我的main.xml是什么是关键商店和如何实施谷歌地图

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainlayout" 
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:clickable="true" 
    android:enabled="true" 
    android:apiKey="0mT--u1GbHdhnBJgPZU8zhoF2e4qdpCag32e7lQ" /> 

和java文件

package de.vogella.android.locationapi.maps; 

import android.content.Context; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.widget.RelativeLayout; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 

public class ShowMap extends MapActivity { 

private MapController mapController; 
private MapView mapView; 
private LocationManager locationManager; 

public void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.main); // bind the layout to the activity 

    // create a map view 
    RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout); 
    mapView = (MapView) findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 
    mapView.setStreetView(true); 
    mapController = mapView.getController(); 
    mapController.setZoom(14); // Zoon 1 is world view 
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 
      0, new GeoUpdateHandler()); 
} 

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

public class GeoUpdateHandler implements LocationListener { 

    @Override 
    public void onLocationChanged(Location location) { 
     int lat = (int) (location.getLatitude() * 1E6); 
     int lng = (int) (location.getLongitude() * 1E6); 
     GeoPoint point = new GeoPoint(lat, lng); 
     mapController.animateTo(point); // mapController.setCenter(point); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 
    } 

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

}

+0

我投票关闭这一问题作为题外话,因为它很旧,根据特征的弃用目前并不合适,所以它没有更多的有用.. – SRam 2015-06-10 12:22:47

回答

0

我设计出砖将显示而不是实际的地图图像的NI铁路应用程序时出现了问题。这似乎是因为我正在使用我团队中另一个人创建的调试密钥库。一旦我们创建了发布密钥库和发布API密钥,地图就可以正常工作。对你来说可能是一个类似的问题。

0

首先,您需要获取调试密钥库的MD5指纹。这是怎么做的:http://code.google.com/intl/ru-RU/android/add-ons/google-apis/mapkey.html#getdebugfingerprint

请注意,如果您使用发行密钥库和构建应用程序对它(如使用ant版本),你需要获得指纹发布密钥库(但你是sayng你是新来的Android我怀疑你现在正在使用发行密钥库)

然后,你需要在谷歌注册密钥,并获得地图的关键。请点击这个链接:http://code.google.com/intl/ru-RU/android/add-ons/google-apis/mapkey.html#registering

另外,请告诉我,你在哪里得到你当前的地图的关键?如果按上述方法获取,可能是您的应用在AndroidManifest.xml文件中缺少INTERNET权限。

确保你有下面这行你的清单

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