我正在製作一個應用程序,需要顯示我用經度和緯度定義的位置。一切都很好,它會在我的應用程序屏幕上打開Google地圖,但地圖不會顯示出來! 這是我使用的代碼...Android,谷歌地圖不會顯示
public class MapsActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//vraag custom title bar
requestCustomTitle();
setContentView(R.layout.mapsactivity);
//Titel dynamisch invullen volgens taalvoorkeuren, roept methode setCustomTitle op
setCustomTitle(getResources().getString(R.string.MapsTitel));
showZoom();
locate(getIntent().getStringExtra("kantoorLat"), getIntent().getStringExtra("kantoorLng"));
addMarker();
}
/*
* De methode showZoom zorgt ervoor dat de zoombuttons worden getoond
*/
private void showZoom(){
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
}
/*
* De methode locate zorgt ervoor dat de juiste locatie wordt getoond
*/
private void locate(String strlat, String strlng){
mc = mapView.getController();
String coordinates[] = {strlat,strlng};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
/*
* De methode addMarker zorgt ervoor dat er een indicator staat op de locatie
*/
private void addMarker(){
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
}
protected boolean isRouteDisplayed(){
return false;
}
class MapOverlay extends com.google.android.maps.Overlay{
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
super.draw(canvas, mapView, shadow);
Point screenPts = new Point();
mapView.getProjection().toPixels(p,screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.accentindicator);
canvas.drawBitmap(bmp, screenPts.x+7, screenPts.y-19, null);
return true;
}
}
,所以你看到的只是電網吧?你有沒有指定地圖API密鑰? – WarrenFaith 2011-04-08 09:54:40
你給了正確的API密鑰嗎?和'InternetPermissions'到您的應用程序? – 2011-04-08 09:57:07
我在佈局XML文件中指定了我的API密鑰。我看到了網格,Google的徽標和我的標記。 – Hannelore 2011-04-08 09:57:45